HarmonyLib.HarmonyException: Patching exception in method System.Void Verse.Map::FillComponents() ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: Transpiler pattern 'FillComponents_CheckRand' was expected to match at least 1 times, but matched 0 times (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
Error analysis The error message indicates that there is an issue when patching the `Verse.Map::FillComponents()` method using HarmonyLib. Specifically, a transpiler pattern named `FillComponents_CheckRand` was expected to match at least once in the target method, but it didn't match any part of the method's code. Possible reasons 1. Incorrect pattern: The pattern defined in the transpiler might be wrong. It could be due to incorrect opcode sequences, operand values, or the pattern might not exist in the target method's IL code. 2. Method signature or implementation change: The `FillComponents` method might have been updated, and the pattern no longer matches the new IL code. 3. Harmony patching order: If there are multiple patches on the same method, the order of patching might affect the IL code, causing the pattern to fail. Suggested solution 1. Verify the pattern: Double - check the `FillComponents_CheckRand` pattern. Make sure the opcode sequences and operand values are correct. You can use a tool like ILSpy to view the IL code of the `FillComponents` method and compare it with your pattern. 2. Handle pattern mismatch gracefully: Instead of expecting the pattern to match at least once, you can add some error handling in your transpiler code. For example, if the pattern doesn't match, you can log a warning and return the original instructions. 3. Check for method changes: If the `FillComponents` method has been updated, you need to update your pattern accordingly. Here is an example of how you can handle the pattern mismatch gracefully in your transpiler code: ```csharp using HarmonyLib; using System.Collections.Generic; using System.Reflection.Emit; // Assume this is your transpiler method [HarmonyPatch(typeof(Verse.Map), "FillComponents")] class FillComponentsTranspiler { static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> instructionList = new List<CodeInstruction>(instructions); // Try to find the pattern int matchCount = FindPattern(instructionList); if (matchCount == 0) { // Pattern not found, log a warning and return the original instructions UnityEngine.Debug.LogWarning("FillComponents_CheckRand pattern not found. Returning original instructions."); return instructionList; } // If the pattern is found, do your patching here //... return instructionList; } static int FindPattern(List<CodeInstruction> instructions) { // Implement your pattern matching logic here // Return the number of times the pattern is found return 0; } } ``` I in the past development process, encountered the following points need to be especially careful to deal with: 1. When using transpilers, always make sure to test your patterns on different versions of the target method. Method implementations can change, and your pattern might break. 2. Be aware of the Harmony patching order. If you have multiple patches on the same method, the order can affect the IL code and cause unexpected behavior. 3. Use proper logging in your transpiler code. This will help you debug issues when the pattern doesn't match or when there are other problems during patching. [2026-02-08 11:18:14 | AI写代码神器 | 730点数解答]
- [字节豆包] HarmonyLib.HarmonyException: Patching exception in method System.Void Verse.Map::FillComponents() ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: Transpiler pattern 'FillComponents_CheckRand' was expected to match at least 1 times, but matched 0 times (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)(730点数解答 | 2026-02-08 11:18:14)3
- [DeepSeek] Patching exception in method System.Void Verse.AI.JobDriver::Cleanup(Verse.AI.JobCondition condition)[Ref 3AFC4070] at HarmonyLib.PatchClassProcessor.ReportException (System.Exception exception, System.Reflection.MethodBase original) [0x00154] in <b994eb69d2df47fdb01add71b9ac29d2>:0 at HarmonyLib.PatchClassProcessor.RunMethod[S] (System.Exception& exception, System.Object[] parameters) [0x00071] in <b994eb69d2df47fdb01add71b9ac29d2>:0 at HarmonyLib.PatchClassProcessor.Patch () [0x00084] (344点数解答 | 2025-08-14 16:29:32)131
- [字节豆包] exception in verse.ai.jobdriver.checkcurrenttoilendorfail: system.indexoutofrangeexception: index was outside the bounds of the array. [ref 40ee905d] at verse.edificegrid.get_item (verse.intvec3 c) [0x00017] in <69945a8ed6c540cf90b578de735e0605>:0 at verse.gridsutility.getedifice (verse.intvec3 c, verse.map map) [0x00000] in <69945a8ed6c540cf90b578de735e0605>:0 at verse.ai.reservationutility.reservesittableorspot (verse.pawn pawn, verse.intvec3 exactsittingpos, verse.ai.job job, system.bool(65点数解答 | 2024-12-06 19:46:33)428
- [讯飞星火] skill={ trigger:{ player:"shaBegin", }, direct:true, filter:function (event,player){ return event.target.hp>0&&event.target.countCards('he')>0; }, audio:2, logTarget:"target", content:function (){ 'step 0' player.choosePlayerCard(trigger.target,'he', [1,Math.min(trigger.target.countCards('he'),trigger.target.hp)],get.prompt('pojun',trigger.target)); 'step 1' if(result.bool&&result.links.length){ player.logSkill('xinpojun'); if(trigger.target.storage.xinpojun2){ trigger.target.storage.xinpojun2=t(288点数解答 | 2025-07-06 23:39:34)181
- [字节豆包] 翻译以下代码;skill={ audio:3, trigger:{ player:"phaseUseBegin", }, filter:function(event,player){ return game.hasPlayer(target=>target!=player&&!target.isZhu2()); }, direct:true, content:function(){ 'step 0' player.chooseTarget(get.prompt('sbwusheng'),'选择一名非主公的其他角色,本阶段对其使用【杀】无距离和次数限制,使用【杀】指定其为目标后摸一张牌,对其使用五张【杀】后不能对其使用【杀】',(card,player,target)=>{ return target!=player&&!target.isZhu2(); }).set('ai',target=>{ var (522点数解答 | 2025-05-24 13:13:19)240
- [讯飞星火] skill={ trigger:{ player:"shaBegin", }, direct:true, filter:function (event,player){ return event.target.hp>0&&event.target.countCards('he')>0; }, audio:2, logTarget:"target", content:function (){ 'step 0' player.choosePlayerCard(trigger.target,'he', [1,Math.min(trigger.target.countCards('he'),trigger.target.hp)],get.prompt('pojun',trigger.target)); 'step 1' if(result.bool&&result.links.length){ (286点数解答 | 2025-07-06 23:35:52)186
- [字节豆包] public static class checkPattern(String regex, String tip) { boolean flag; do { Scanner sc = new Scanner(System.in); String info = sc.next(); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(info); if (!matcher.find()) { System.out.print(tip + "格式错误!请重新输入:"); flag = true; } else { break; } sc.close(); // 增加资源释放 } while (flag); } public class example (510点数解答 | 2025-04-29 15:33:18)220
- [DeepSeek] #include <iostream> #include <vector> #include <algorithm> int main() { int n; std::cin >> n; std::vector<int> times(n); for (int i = 0; i < n; ++i) { std::cin >> times[i]; } std::sort(times.begin(), times.end()); int total = 0; for (int i = 0; i < 5; ++i) { total += times[i]; } std::cout << total << std::endl; return 0; }(263点数解答 | 2026-01-17 10:23:32)18
- [字节豆包] 下面这段代码提示:Map<K,V> is not applicable for the arguments (Object, Object),如何解决 @Override public void put(Object key, Object value, Long expireSecond) { map.put(key, value); expirationTimes.put(key, System.currentTimeMillis() + expireSecond * 1000); }(195点数解答 | 2025-01-17 10:30:53)205
- [字节豆包] content: async function(event, trigger, player) { const [target] = event.targets; const [card] = event.cards; trigger.cancel(); await player.discard(event.cards); const { result } = await player.chooseControlList( true, function(event, player) { const target = _status.event.target; let att = get.attitude(player, target); if (target.hasSkillTag("maihp")) att = -att; return att > 0 ? 0 : 1; }, ["令" (179点数解答 | 2025-05-17 20:49:48)194
- [DeepSeek] content() { "step 0"; player.loseHp(); event.target = trigger.player; "step 1"; event.addIndex = 0; var list = [], num = target.countCards("h") - player.countCards("h"); event.num = num; if (num > 0 && target.countCards("h") > 0) list.push("令其弃置" + get.cnNumber(num) + "张手牌"); else event.addIndex++; if (target.hp > player.hp) list.push("令其失去" + get.cnNumber(target.hp - player.hp) + "点体力"); if (!lis(313点数解答 | 2025-05-28 16:03:47)208
- [字节豆包] def hanoi(n, source, target, auxiliary): if n == 1: print(f"Move disk 1 from {source} to {target}") else: # 将n-1个盘子从source移动到auxiliary(借助target) hanoi(n-1, source, auxiliary, target) # 移动第n个盘子 print(f"Move disk {n} from {source} to {target}") # 将n-1个盘子从auxiliary移动到target(借助source) hanoi(n-1, auxiliary, target, source) # 示例:移动3个盘子,从A到C,借助B hanoi(3, 'A', 'C', 'B') (386点数解答 | 2025-06-17 14:19:42)155