static void Prefix(NpcAppearModule __instance, ref Dictionary <int, NpcAppearDBData> ___m_NpcAppearDBDataDir) { return; if (!enabled) { return; } NpcAppearDBData phyllisData = ___m_NpcAppearDBDataDir[4000035]; NpcAppear phyllisAppear = ActorMgr.Self.Get(4000035).GetComponent <NpcAppear>(); foreach (ClothesChanger cc in noClothes) { continue; ___m_NpcAppearDBDataDir.Add(cc.id, phyllisData); Actor actor = ActorMgr.Self.Get(cc.id); actor.gameObject.AddComponent <NpcAppear>(); NpcAppear component = actor.GetComponent <NpcAppear>(); AccessTools.FieldRefAccess <NpcAppear, Dictionary <int, AppearDBData> >(component, "m_DefaultAppearDBDatas") = AccessTools.FieldRefAccess <NpcAppear, Dictionary <int, AppearDBData> >(phyllisAppear, "m_DefaultAppearDBDatas"); AccessTools.FieldRefAccess <NpcAppear, int[]>(component, "defaultAppearIDs") = AccessTools.FieldRefAccess <NpcAppear, int[]>(phyllisAppear, "defaultAppearIDs"); AccessTools.FieldRefAccess <NpcAppear, Transform>(component, "m_BoneRoot") = AccessTools.FieldRefAccess <NpcAppear, Transform>(phyllisAppear, "m_BoneRoot"); AccessTools.FieldRefAccess <NpcAppear, SkinnedMeshRenderer[]>(component, "m_Smrs") = AccessTools.FieldRefAccess <NpcAppear, SkinnedMeshRenderer[]>(phyllisAppear, "m_Smrs"); //component.InitAppear(phyllisData, phyllisAppear.appearData, actor); typeof(NpcAppearModule).GetMethod("InitNPCAppear", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { cc.id, phyllisAppear.appearData, phyllisAppear.npcAppearDBData }); //typeof(NpcAppear).GetProperty("appearData").SetValue(component, phyllisAppear.appearData, null); //AccessTools.FieldRefAccess<NpcAppear, Dictionary<int, AppearDBData>>(component, "m_DefaultAppearDBDatas") = AccessTools.FieldRefAccess<NpcAppear, Dictionary<int, AppearDBData>>(phyllisAppear, "m_DefaultAppearDBDatas"); //AccessTools.FieldRefAccess<NpcAppear, Actor>(component, "m_Actor") = actor; } }
static void Postfix(Actor npcActor, TeeterGameCtr __instance, ref bool ___playing, ref bool ___waitForInput, ref float ___startInputTime, ref float ___curTime, TeeterActorCtr ___player, TeeterActorCtr ___npc, ref WhiteCat.Tween.Tweener ___teeterTW, ref int ___gameScores, ref int ___teeterDir) { lastTeeterActor = npcActor; if (!enabled || !settings.ReplaceTeeterTotterGame || !CanTeeterInteract(npcActor)) { return; } teeterGameRunning = true; ___teeterTW.enabled = false; //___teeterDir = 0; Transform t1 = AccessTools.FieldRefAccess <TeeterActorCtr, GameObject>(___player, "tempmodel").transform; Transform t2 = AccessTools.FieldRefAccess <TeeterActorCtr, GameObject>(___npc, "tempmodel").transform; Vector3 midpoint = (t1.position + t2.position) / 2; Player.Self.actor.gamePos = new Vector3(214.5f, 48.4f, -68.5f); lastTeeterActor.gamePos = new Vector3(216.0f, 48.4f, -69.8f); for (int i = 0; i < AccessTools.FieldRefAccess <TeeterActorCtr, GameObject>(___player, "tempmodel") .GetComponentsInChildren <Renderer>(true).Length; i++) { AccessTools.FieldRefAccess <TeeterActorCtr, GameObject>(___player, "tempmodel").GetComponentsInChildren <Renderer>(true)[i].enabled = false; } for (int i = 0; i < AccessTools.FieldRefAccess <TeeterActorCtr, GameObject>(___npc, "tempmodel") .GetComponentsInChildren <Renderer>(true).Length; i++) { AccessTools.FieldRefAccess <TeeterActorCtr, GameObject>(___npc, "tempmodel").GetComponentsInChildren <Renderer>(true)[i].enabled = false; } }
public static void AddEnchantment_Postfix(Tool __instance, ref bool __result, BaseEnchantment enchantment) { if (enchantment != null && __instance is Slingshot && enchantment.IsSecondaryEnchantment()) { var lastUser = AccessTools.FieldRefAccess <Tool, Farmer>("lastUser"); //__instance.RemoveEnchantment(enchantment); __instance.enchantments.Remove(enchantment); enchantment.UnapplyTo(__instance, lastUser(__instance)); foreach (BaseEnchantment existing_enchantment in __instance.enchantments) { if (enchantment.GetType() == existing_enchantment.GetType()) { if (existing_enchantment.GetMaximumLevel() < 0 || existing_enchantment.GetLevel() < existing_enchantment.GetMaximumLevel()) { existing_enchantment.SetLevel(__instance, existing_enchantment.GetLevel() + 1); __result = true; return; } __result = false; return; } } __instance.enchantments.Add(enchantment); enchantment.ApplyTo(__instance, lastUser(__instance)); __result = true; return; } }
static void write(SoEnemyArray ____SoEnemyArray, string fileName, string variableName) { var reflector = new Reflector <SoEnemyData>(); var header = reflector.GetHeader(); header.Insert(0, "JapaneseName"); header.Insert(0, "EnglishName"); var values = new List <Dictionary <string, string> >(); foreach (OcEm enemy in ____SoEnemyArray.EmArray) { try { var e = AccessTools.FieldRefAccess <OcEm, SoEnemyData>(enemy, variableName); var value = reflector.GetTargetValues(e); LanguageUtils.English(); value["EnglishName"] = e.Name; LanguageUtils.Japanese(); value["JapaneseName"] = e.Name; values.Add(value); } catch { } } SingletonMonoBehaviour <FileWriter> .Inst.Write(fileName, header, values); }
public VanillaStorytellersWinstonWaves(ModContentPack mod) { // RNG { PatchingUtilities.PatchSystemRandCtor("VSEWW.Window_ChooseReward", false); } // Dialogs { var type = chooseRewardDialogType = AccessTools.TypeByName("VSEWW.Window_ChooseReward"); choosenRewardField = AccessTools.FieldRefAccess <Def>(type, "choosenReward"); type = AccessTools.TypeByName("VSEWW.RewardDef"); MpCompat.harmony.Patch(AccessTools.Method(type, "DrawCard"), transpiler: new HarmonyMethod(typeof(VanillaStorytellersWinstonWaves), nameof(ReplaceButton))); MP.RegisterSyncMethod(typeof(VanillaStorytellersWinstonWaves), nameof(SyncedChooseReward)); // The window is always visible and its default position covers MP chat button // This patch will move it under the button (if MP is on), // especially considering that it'll move up on autosave/joinstate creation type = AccessTools.TypeByName("VSEWW.Window_WaveCounter"); MpCompat.harmony.Patch(AccessTools.Method(type, "SetInitialSizeAndPosition"), postfix: new HarmonyMethod(typeof(VanillaStorytellersWinstonWaves), nameof(PostSetInitialSizeAndPosition))); MP.RegisterPauseLock(PauseIfDialogOpen); } LongEventHandler.ExecuteWhenFinished(LatePatch); }
public AnimalTab(ModContentPack mod) { var type = AccessTools.TypeByName("AnimalTab.Command_HandlerSettings"); commandCtor = AccessTools.Constructor(type, new[] { AccessTools.TypeByName("AnimalTab.CompHandlerSettings") }); compField = AccessTools.FieldRefAccess <ThingComp>(type, "comp"); MP.RegisterSyncMethod(type, "MassSetMode").SetContext(SyncContext.MapSelected); MP.RegisterSyncMethod(type, "MassSetHandler").SetContext(SyncContext.MapSelected); MP.RegisterSyncMethod(type, "MassSetLevel").SetContext(SyncContext.MapSelected); MP.RegisterSyncWorker <Command_Action>(SyncHandlerSettingsCommand, type); type = AccessTools.TypeByName("AnimalTab.PawnColumnWorker_Handler"); MpCompat.RegisterLambdaDelegate(type, "DoHandlerFloatMenu", 0, 1, 2); MpCompat.RegisterLambdaDelegate(type, "DoMassHandlerFloatMenu", 0, 1, 4); MpCompat.harmony.Patch(AccessTools.Method(type, nameof(PawnColumnWorker.DoHeader)), prefix: new HarmonyMethod(typeof(AnimalTab), nameof(PreDoHeader)), postfix: new HarmonyMethod(typeof(AnimalTab), nameof(StopWatch))); MpCompat.harmony.Patch(AccessTools.Method(type, nameof(PawnColumnWorker.DoCell)), prefix: new HarmonyMethod(typeof(AnimalTab), nameof(PreDoCell)), postfix: new HarmonyMethod(typeof(AnimalTab), nameof(StopWatch))); type = compHandlerSettingsType = AccessTools.TypeByName("AnimalTab.CompHandlerSettings"); modeField = MP.RegisterSyncField(type, "_mode"); levelField = MP.RegisterSyncField(type, "_level"); }
static SpawnPmcPatch() { targetInterface = PatcherConstants.TargetAssembly.GetTypes().Single(IsTargetInterface); targetType = PatcherConstants.TargetAssembly.GetTypes().Single(IsTargetType); wildSpawnTypeField = AccessTools.FieldRefAccess <WildSpawnType>(targetType, "Type"); botDifficultyField = AccessTools.FieldRefAccess <BotDifficulty>(targetType, "BotDifficulty"); }
public SmartMedicine(ModContentPack mod) { // Stock up medicine/drugs { var type = AccessTools.TypeByName("SmartMedicine.StockUpUtility"); var pasteMethod = AccessTools.Method(type, "StockUpPasteSettings"); stockUpPasteMethod = AccessTools.MethodDelegate <StockUpPasteSettingsDelegate>(pasteMethod); stockUpSettingsMethod = AccessTools.MethodDelegate <StockUpSettingsDelegate>(AccessTools.Method(type, "StockUpSettings")); MpCompat.harmony.Patch(pasteMethod, prefix: new HarmonyMethod(typeof(SmartMedicine), nameof(PrePasteSettings))); MpCompat.harmony.Patch(AccessTools.Method(type, "SetStockCount", new[] { typeof(Pawn), typeof(ThingDef), typeof(int) }), prefix: new HarmonyMethod(typeof(SmartMedicine), nameof(PreSetStockCount))); // Mod methods to sync MP.RegisterSyncMethod(AccessTools.Method(type, "StockUpStop", new[] { typeof(Pawn), typeof(ThingDef) })); MP.RegisterSyncMethod(AccessTools.Method(type, "StockUpClearSettings")); // Our methods to sync MP.RegisterSyncMethod(typeof(SmartMedicine), nameof(SyncedSetStockCount)); MP.RegisterSyncMethod(typeof(SmartMedicine), nameof(SyncedPasteSettings)); // We'll need the access to copiedPawn field to modify it when pasting smartMedicineCompType = AccessTools.TypeByName("SmartMedicine.SmartMedicineGameComp"); copiedPawnField = AccessTools.FieldRefAccess <Pawn>(smartMedicineCompType, "copiedPawn"); } // Set wound target tend quality { var type = AccessTools.TypeByName("SmartMedicine.HediffRowPriorityCare"); MpCompat.RegisterLambdaDelegate(type, "LabelButton", 0, 1); } }
static void Postfix(HomeItemSelector __instance, Area ___area, ref ISelector ___focusSelector, ref GameObject ___previewGameObj, ItemHomeSystemUnitCmpt ___systemCmpt) { if (!enabled || !(___focusSelector is FarmViewer) || ___area == null || ___previewGameObj == null || (___systemCmpt != null && !___systemCmpt.ContainsRegionType(HomeRegionType.Farm))) { return; } Vector3 vector2 = GetValidPos(___previewGameObj.transform.position); if (vector2 != Vector3.zero) { ___previewGameObj.transform.position = vector2; } else { return; } List <GameObject> ___highlights = AccessTools.FieldRefAccess <RegionViewer, List <GameObject> >(___focusSelector as RegionViewer, "highlights"); for (int j = 0; j < ___area.Length; j++) { Vector3 vector = GetValidPos(___highlights[j].transform.position); if (vector != Vector3.zero) { ___highlights[j].transform.position = vector; } } AccessTools.FieldRefAccess <RegionViewer, List <GameObject> >(___focusSelector as RegionViewer, "highlights") = ___highlights; }
public IEnumerator Apply(ICollection <Enchant> elements) { yield return(Task.Run(() => { var enchants = elements.ToArray(); var all = enchants.Select(e => (SoEnchantment)e).ToArray(); AccessTools.FieldRefAccess <SoDataList <SoEnchantDataList, SoEnchantment>, SoEnchantment[]>(OcResidentData.EnchantDataList, "all") = all; setupTreasureProb(enchants); foreach (var enchant in elements) { if (enchant.ProbInRandomDrop > 0.0f) { EnchantHelper.Inst.UnspecifiedEnemyDrop[enchant.Id] = enchant.ProbInRandomDrop; } if (enchant.ProbInStoneDrop > 0.0f) { EnchantHelper.Inst.StoneRandomDrop[enchant.Id] = enchant.ProbInStoneDrop; } if (enchant.ProbInTreeDrop > 0.0f) { EnchantHelper.Inst.TreeRandomDrop[enchant.Id] = enchant.ProbInTreeDrop; } EnchantHelper.Inst.SpecifiedEnemyDrop[enchant.Id] = enchant.ProbInEnemyDrop; } }).LogError().AsCoroutine()); }
private static void ChangeClothes(Actor actor, int hairId, int clothesId) { if (!enabled) { return; } Dictionary <int, AppearDBData> appearDbDatas = AccessTools.FieldRefAccess <NpcAppearModule, Dictionary <int, AppearDBData> >(NpcAppearModule.Self, "m_AppearDBDataDic"); Dbgl($"changing clothes for {actor.ActorName}"); NpcAppear component = actor.GetComponent <NpcAppear>(); if (component == null || !appearDbDatas.ContainsKey(hairId) || !appearDbDatas.ContainsKey(clothesId)) { Dbgl($"no npcappear for {actor.ActorName}"); return; } if (hairId > -1) { component.SetPart(appearDbDatas[hairId]); } if (clothesId > -1) { component.SetPart(appearDbDatas[clothesId]); } }
private static void SetIgnoreSeasons(bool ignore) { List <SeedItemConfData> seedDataList; if (ignore) { seedDataList = AccessTools.FieldRefAccess <ItemDataMgr, List <SeedItemConfData> >(Module <ItemDataMgr> .Self, "seedDataList"); for (int i = 0; i < seedDataList.Count; i++) { seedDataList[i].growthRate = new int[] { 10, 10, 10, 10 }; if (seedDataList[i].fruitGrowthRate.Length == 4) { seedDataList[i].fruitGrowthRate = new int[] { 10, 10, 10, 10 }; } } AccessTools.FieldRefAccess <ItemDataMgr, List <SeedItemConfData> >(Module <ItemDataMgr> .Self, "seedDataList") = seedDataList; } else { SqliteDataReader reader = LocalDb.cur.ReadFullTable("Item_seed"); seedDataList = DbReader.Read <SeedItemConfData>(reader, 20); } ModifyPlants(ref seedDataList); AccessTools.FieldRefAccess <ItemDataMgr, List <SeedItemConfData> >(Module <ItemDataMgr> .Self, "seedDataList") = seedDataList; }
private static void LateSyncMethods() { // Artillery fix { var type = AccessTools.TypeByName("VFESecurity.CompLongRangeArtillery"); selectedCompsProperty = AccessTools.Property(type, "SelectedComps"); targetedTileField = AccessTools.FieldRefAccess <GlobalTargetInfo>(type, "targetedTile"); resetWarmupTicksMethod = AccessTools.DeclaredMethod(type, "ResetWarmupTicks"); MP.RegisterSyncMethod(type, "ResetForcedTarget"); MP.RegisterSyncMethod(typeof(VFESecurity), nameof(SetTargetedTile)); MpCompat.harmony.Patch(AccessTools.Method(type, "SetTargetedTile"), new HarmonyMethod(typeof(VFESecurity), nameof(Prefix))); } // RNG fix { var methods = new[] { // ArtilleryComp:TryResolveArtilleryCount is called by ArtilleryComp:CompTick "VFESecurity.ArtilleryComp:BombardmentTick", "VFESecurity.ArtilleryComp:TryStartBombardment", "VFESecurity.Building_Shield:Notify_EnergyDepleted", "VFESecurity.Building_Shield:Draw", "VFESecurity.CompLongRangeArtillery:CompTick", }; PatchingUtilities.PatchPushPopRand(AccessTools.Method("VFESecurity.Building_Shield:AbsorbDamage", new[] { typeof(float), typeof(DamageDef), typeof(float) })); PatchingUtilities.PatchPushPopRand(methods); } }
private static void OpenBackpack() { /* * backpack = Instantiate(ZNetScene.instance.GetPrefab("piece_chest")); * if (backpack.GetComponent<WearNTear>()) * Destroy(backpack.GetComponent<WearNTear>()); * if (backpack.GetComponent<Piece>()) * Destroy(backpack.GetComponent<Piece>()); * if (backpack.transform.Find("New")) * Destroy(backpack.transform.Find("New").gameObject); * if (backpack.GetComponent<ZNetView>()) * Destroy(backpack.GetComponent<ZNetView>()); * backpack.transform.SetParent(Player.m_localPlayer.transform); * backpack.transform.position = Player.m_localPlayer.transform.position; * Container c = backpack.GetComponent<Container>(); */ backpackContainer = Player.m_localPlayer.gameObject.GetComponent <Container>(); if (backpackContainer == null) { backpackContainer = Player.m_localPlayer.gameObject.AddComponent <Container>(); } backpackContainer.m_name = backpackName.Value; //AccessTools.FieldRefAccess<Inventory, Sprite>(backpackInventory, "m_bkg") = c.m_bkg; AccessTools.FieldRefAccess <Container, Inventory>(backpackContainer, "m_inventory") = backpackInventory; InventoryGui.instance.Show(backpackContainer); }
private void setupTreasureProb(IList <Item> elements) { var itemManager = OcItemDataMng.Inst; var itemList = AccessTools.FieldRefAccess <OcItemDataMng, SoItemDataList>(itemManager, "SoItemDataList"); var probSums = AccessTools.FieldRefAccess <SoItemDataList, float[]>(itemList, "rarityChestProbSums"); for (int i = 0; i < ItemHelper.Inst.MaxRarity; i++) { ref var probs = ref AccessTools.FieldRefAccess <SoItemDataList, float[]>(itemList, $"rarity{i + 1}ChestProbs"); probs = new float[elements.Count]; float sum = 0; for (int j = 0; j < elements.Count; j++) { var item = elements[j]; if (item.ProbsInTreasureBox == null) { continue; } var p = item.ProbsInTreasureBox[i]; if (!(p > 0)) { continue; } probs[j] = p; sum += p; } probSums[i] = sum; }
static void Prefix(PatrolArea __instance) { //Dbgl($"npc name: {__instance.actor.Value.ActorName}"); if (__instance.actor.Value.InstanceId != 4000044) { return; } int _ridableId = Module <RidableModuleManager> .Self.GetNpcRidableUID(__instance.actor.Value.InstanceId); Dbgl($"ridable id: {_ridableId}"); foreach (IRidable r in AccessTools.FieldRefAccess <RidableModuleManager, List <IRidable> >(Module <RidableModuleManager> .Self, "allRidable")) { Dbgl($"ridable id: {r.UID} name: {r.GetNickName()}, owner: {r.GetBelongRider().GetName()}"); } IRidable _ridable = Module <RidableModuleManager> .Self.GetRidable(_ridableId); if (_ridable == null) { Dbgl($"ridable is null"); return; } Dbgl($"PatrolArea OnStart: {_ridableId} {_ridable.GetNickName()}"); return; foreach (KeyValuePair <int, RidableTransactionSaveData> kvp in AccessTools.FieldRefAccess <RidableModuleManager, Dictionary <int, RidableTransactionSaveData> >(Module <RidableModuleManager> .Self, "ridableTransactionDataDic")) { int id = kvp.Key; Dbgl($"got dic entry {id} {kvp.Value.BelongActorID} ActorName: {__instance.actor.Value.ActorName} ActorId: {__instance.actor.Value.InstanceId}"); } }
private static void LatePatch() { // Window_Psyker psykerWindowType = AccessTools.TypeByName("Corruption.Psykers.Window_Psyker"); psykerWindowCompField = AccessTools.FieldRefAccess <ThingComp>(psykerWindowType, "comp"); MP.RegisterSyncMethod(typeof(CorruptionPsykers), nameof(SyncedAddMinorDiscipline)); MpCompat.harmony.Patch(AccessTools.Method(psykerWindowType, nameof(Window.DoWindowContents)), prefix: new HarmonyMethod(typeof(CorruptionPsykers), nameof(PrePsykerDoWindowContents)), postfix: new HarmonyMethod(typeof(CorruptionPsykers), nameof(PostPsykerDoWindowContents))); MP.RegisterSyncMethod(typeof(CorruptionPsykers), nameof(SyncedTryLearnPower)); var psykerLearnablePowerType = AccessTools.TypeByName("Corruption.Core.Abilities.LearnableAbility"); var type = AccessTools.TypeByName("Corruption.Psykers.CompPsyker"); compPsykerTryLearnAbilityMethod = MethodInvoker.GetHandler(AccessTools.Method(type, "TryLearnAbility", new[] { psykerLearnablePowerType })); compPsykerMainDisciplineField = AccessTools.FieldRefAccess <Def>(type, "MainDiscipline"); compPsykerMinorDisciplinesField = AccessTools.FieldRefAccess <IList>(type, "minorDisciplines"); compPsykerXpSyncField = MP.RegisterSyncField(type, "PsykerXP"); type = AccessTools.TypeByName("Corruption.Psykers.PsykerDisciplineDef"); psykerDisciplineDefAbilitiesField = AccessTools.FieldRefAccess <IList>(type, "abilities"); var database = typeof(DefDatabase <>).MakeGenericType(type); getDefByShortHash = MethodInvoker.GetHandler(AccessTools.Method(database, "GetByShortHash")); MpCompat.harmony.Patch(AccessTools.Method(psykerWindowType, "DrawSelectedPower"), transpiler: new HarmonyMethod(typeof(CorruptionPsykers), nameof(Transpiler))); }
private void setupTreasureProb(IList <Enchant> elements) { var enchantList = OcResidentData.EnchantDataList; var maxId = elements.Select(e => e.Id).Max(); var probSums = AccessTools.FieldRefAccess <SoEnchantDataList, float[]>(enchantList, "rarityChestProbSums"); for (int i = 0; i < EnchantHelper.Inst.MaxRarity; i++) { ref var probs = ref AccessTools.FieldRefAccess <SoEnchantDataList, float[]>(enchantList, $"rarity{i}ChestProbs"); probs = new float[elements.Count]; float sum = 0; for (int j = 0; j < elements.Count; j++) { var enchant = elements[j]; if (enchant.ProbsInTreasureBox == null) { continue; } var p = enchant.ProbsInTreasureBox[i]; if (!(p > 0)) { continue; } probs[j] = p; sum += p; } probSums[i] = sum; }
static void Postfix(NpcAppearDBData npcAppearDBData, NpcAppearData appearData, Actor actor) { if (!enabled) { return; } for (int i = 0; i < clothesChangers.Count; i++) { //Dbgl($"changing for {i} {clothesChangers[i].name}"); if (clothesChangers[i].id == actor.InstanceId) { Dbgl($"actor: {actor.ActorName}"); Dictionary <int, AppearDBData> appearDbDatas = AccessTools.FieldRefAccess <NpcAppearModule, Dictionary <int, AppearDBData> >(Module <NpcAppearModule> .Self, "m_AppearDBDataDic"); NpcAppear component = actor.GetComponent <NpcAppear>(); if (component == null) { Dbgl("actor does not have npcappear"); return; } Dbgl($"i {i} hair setting {settings.hairs[i]} actor hair: {hairs[settings.hairs[i]]}"); //if(settings.hairs[i] != 0) component.SetPart(appearDbDatas[hairs[settings.hairs[i]]]); Dbgl($"actor clothes: {clothes[settings.clothes[i]]}"); //if (settings.clothes[i] != 0) component.SetPart(appearDbDatas[clothes[settings.clothes[i]]]); } } }
public static List <EntryData> GetEntries(this CategoryContentPanel instance) { fieldRef_Assets_ ??= AccessTools.FieldRefAccess <CategoryContentPanel, List <EntryData> >("m_Assets"); var assets = fieldRef_Assets_ as AccessTools.FieldRef <CategoryContentPanel, List <EntryData> >; return(assets(instance)); }
public CashRegister(ModContentPack mod) { var type = AccessTools.TypeByName("CashRegister.Shifts.ITab_Register_Shifts"); MpCompat.RegisterLambdaMethod(type, "GetGizmos", 1).SetContext(SyncContext.MapSelected); MP.RegisterSyncWorker <object>(NoSync, type, shouldConstruct: true); MP.RegisterSyncMethod(typeof(CashRegister), nameof(SyncedSetShifts)).ExposeParameter(1).ExposeParameter(2).ExposeParameter(3).ExposeParameter(4).ExposeParameter(5).MinTime(100); MpCompat.harmony.Patch(AccessTools.Method(type, "FillTab"), prefix: new HarmonyMethod(typeof(CashRegister), nameof(PreFillTab)), postfix: new HarmonyMethod(typeof(CashRegister), nameof(PostFillTab))); type = AccessTools.TypeByName("CashRegister.Gizmo_Radius"); gizmoRadiusConstructor = AccessTools.GetDeclaredConstructors(type).First(x => x.GetParameters().Length == 1); gizmoSelectionField = AccessTools.FieldRefAccess <Building[]>(type, "selection"); MP.RegisterSyncMethod(AccessTools.DeclaredMethod(type, "ButtonDown")); MP.RegisterSyncMethod(AccessTools.DeclaredMethod(type, "ButtonUp")); MP.RegisterSyncMethod(AccessTools.DeclaredMethod(type, "ButtonCenter")); MP.RegisterSyncWorker <Gizmo>(SyncGizmoRadius, type); type = AccessTools.TypeByName("CashRegister.Building_CashRegister"); cashRegisterType = type.MakeArrayType(); shiftsListField = AccessTools.FieldRefAccess <IList>(type, "shifts"); type = AccessTools.TypeByName("CashRegister.Shifts.Shift"); shiftConstructor = AccessTools.Constructor(type); timetableField = AccessTools.FieldRefAccess <object>(type, "timetable"); assignedField = AccessTools.FieldRefAccess <List <Pawn> >(type, "assigned"); type = AccessTools.TypeByName("CashRegister.Timetable.TimetableBool"); timesField = AccessTools.FieldRefAccess <List <bool> >(type, "times"); }
public static void DropHardwood(Tree tree, int index, int x, int y, int number, GameLocation location) { if (!dropDict.ContainsKey(tree.treeType.Value.ToString())) { Game1.createMultipleObjectDebris(index, x, y, number, location); } else { Random r; if (Game1.IsMultiplayer) { Game1.recentMultiplayerRandom = new Random(x * 1000 + y); r = Game1.recentMultiplayerRandom; } else { r = new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed + x * 7 + y * 11); } foreach (var item in dropDict[tree.treeType.Value.ToString()].hardwood) { int amount = GetDropAmount(item); if (Game1.getFarmer(AccessTools.FieldRefAccess <Tree, NetLong>(tree, "lastPlayerToHit").Value).professions.Contains(14)) { if (item.min == 0 && item.max == 0) { while (r.NextDouble() < 0.5) { amount++; } } else { amount += (int)(amount * 0.25f + 0.9f); } } amount = (int)Math.Round(amount * item.mult); if (tree.growthStage.Value > 5) { amount += (int)Math.Round(amount * Math.Min(Config.MaxDaysSizeIncrease, tree.growthStage.Value - 5) * Config.LootIncreasePerDay); } //SMonitor.Log($"Dropping {amount}x {item.id}"); if (amount <= 0) { return; } for (int i = 0; i < amount; i++) { Object obj = GetObjectFromID(item.id, 1, GetQuality(item)); if (obj == null) { SMonitor.Log($"error getting object from id {item.id}", StardewModdingAPI.LogLevel.Warn); break; } Game1.createItemDebris(obj, new Vector2(x, y) * 64, Game1.random.Next(4), location, -1); } } } }
private static void LoadSceneTextures(GameObject[] gos) { Dbgl($"loading {gos.Length} scene textures"); outputDump.Clear(); foreach (GameObject gameObject in gos) { if (gameObject.name == "_NetSceneRoot") { continue; } LoadOneTexture(gameObject, gameObject.name, "object"); } GameObject root = AccessTools.FieldRefAccess <ZNetScene, GameObject>(ZNetScene.instance, "m_netSceneRoot"); foreach (Terrain ter in root.GetComponentsInChildren <Terrain>(true)) { Dbgl($"terrain name: {ter.name}, layers {ter.terrainData.terrainLayers.Length}"); foreach (TerrainLayer tl in ter.terrainData.terrainLayers) { Dbgl($"layer name: {tl.name}, d {tl.diffuseTexture}, {tl.maskMapTexture}, n {tl.normalMapTexture}"); } } if (dumpSceneTextures.Value) { string path = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\CustomTextures\\scene_dump.txt"; File.WriteAllLines(path, outputDump); } }
static void Postfix(Container __instance, Inventory ___m_inventory) { if (__instance.m_name.StartsWith("Chest")) { AccessTools.FieldRefAccess <Inventory, int>(___m_inventory, "m_width") = chestWidth.Value; AccessTools.FieldRefAccess <Inventory, int>(___m_inventory, "m_height") = chestHeight.Value; } }
static HarmonyIl2CppMethodPatcher() { try { codeLenGetter = AccessTools.FieldRefAccess <ILGenerator, int>("code_len"); } catch { codeLenGetter = AccessTools.FieldRefAccess <ILGenerator, int>("m_length"); } try { localsGetter = AccessTools.FieldRefAccess <ILGenerator, LocalBuilder[]>("locals"); } catch { } try { localCountGetter = AccessTools.FieldRefAccess <ILGenerator, int>("m_localCount"); } catch { } PatchTools_RememberObject = AccessTools.Method("HarmonyLib.PatchTools:RememberObject").CreateDelegate <PatchTools_RememberObject_Delegate>(); }
public void Test_AccessTools_FieldRefAccess_ByName() { var fieldInfo = typeof(AccessToolsClass).GetField("field1", BindingFlags.Instance | BindingFlags.NonPublic); Assert.NotNull(fieldInfo); var instance = new AccessToolsClass(); var fieldRef = AccessTools.FieldRefAccess <AccessToolsClass, string>("field1"); ref var value = ref fieldRef(instance);
static GetNewBotTemplatesPatch() { _getNewProfileFunc = typeof(BotsPresets) .GetMethod("GetNewProfile", BindingFlags.NonPublic | BindingFlags.Instance) .CreateDelegate(typeof(Func <BotsPresets, BotData, Profile>)) as Func <BotsPresets, BotData, Profile>; _sessionField = AccessTools.FieldRefAccess <ISession>(typeof(BotsPresets), $"{nameof(GInterface23).ToLower()}_0"); }
private static void DisableNagleAlgorithm(WebSocket socket) { TcpClient tcpClient = AccessTools.FieldRefAccess <WebSocket, TcpClient>("_tcpClient")(socket); if (tcpClient != null) { tcpClient.NoDelay = true; } }
static RemoveUsedBotProfilePatch() { // compile-time check _ = nameof(BotData.ChooseProfile); targetInterface = PatcherConstants.TargetAssembly.GetTypes().Single(IsTargetInterface); targetType = PatcherConstants.TargetAssembly.GetTypes().Single(IsTargetType); profilesField = AccessTools.FieldRefAccess <List <Profile> >(targetType, "list_0"); }
static FullBodyBipedIK getArmsControllerIK() { if (Player.main && Player.main.armsController) { var armsController = Player.main.armsController; return(AccessTools.FieldRefAccess <ArmsController, FullBodyBipedIK>(armsController, nameof(ArmsController.ik))); } return(null); }