appendix:harmonyがある時

差分

このページの2つのバージョン間の差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
appendix:harmonyがある時 [2024/12/18 15:21]
fumble
appendix:harmonyがある時 [2024/12/29 00:31] (現在)
fumble
行 62: 行 62:
 static void ILManipulator(ILContext il, MethodBase original, ILLabel retLabel) static void ILManipulator(ILContext il, MethodBase original, ILLabel retLabel)
 static void SomeOtherILManipulator(ILContext ctx, MethodBase orig) static void SomeOtherILManipulator(ILContext ctx, MethodBase orig)
 +</code>
 +
 +渡すときはHarmonyMethod(MethodInfo method)の変換、つまりコンストラクターを呼んで変換させる。
 +<code csharp>
 +var transpilermethod = typeof(トランスパイラーのあるクラス).GetMethod(トランスパイラーのメソッド名);
 +var transpiler = Activator.CreateInstance(typeHarmonyMethod, transpiler);
 </code> </code>
  
行 69: 行 75:
 特に面倒が起こりそうな Transpiler の実装方法を示す。 特に面倒が起こりそうな Transpiler の実装方法を示す。
 <code csharp> <code csharp>
-static object Transpiler(IEnumerable<object> instructions)+static object Transpiler(IEnumerable instructions)
 { {
-    var type = instructions.First().GetType(); +    var enumerator = instructions?.GetEnumerator(); 
-    var fldOpecode = type.GetField("opcode"); +    if (enumerator !null && enumerator.MoveNext())
-    var fldOperand type.GetField("operand")+
-    var newInstructions = Activator.CreateInstance(typeof(List<>).MakeGenericType(type)) as IList; +
-    foreach (var instruction in instructions)+
     {     {
-        var opecode = fldOpecode.GetValue(instruction); +        var type = enumerator.Current.GetType(); 
-        var operand = fldOperand.GetValue(instruction); +        var fldOpecode = type.GetField("opcode"); 
-        if (opecode.Equals(変えたいところのOpCode) && operand.Equals(変えたいところのOperand)+        var fldOperand = type.GetField("operand"); 
-            newInstructions.Add(Activator.CreateInstance(type, 変えたいOpCode, 変えたいOperand)); +        var newInstructions = Activator.CreateInstance(typeof(List<>).MakeGenericType(type)) as IList; 
-        else +        foreach (var instruction in instructions) 
-            newInstructions.Add(instruction);+        { 
 +            var opecode = fldOpecode.GetValue(instruction); 
 +            var operand = fldOperand.GetValue(instruction); 
 +            if (opecode.Equals(変えたいところのOpCode) && operand != null && operand.ToString() == 変えたいところのOperand) 
 +                newInstructions.Add(Activator.CreateInstance(type, 変えたいOpCode, 変えたいOperand)); 
 +            else 
 +                newInstructions.Add(instruction); 
 +        }
     }     }
     return newInstructions;     return newInstructions;
 } }
 </code> </code>
- +引数をIEnumerableで受けて戻り値をobjectとかで宣言してしまいます。\\ 
-引数戻り値も大嘘で宣言します。:-D\\ +引数で貰った IEnumerable<CodeInstruction> を書き換えて返していいのかがわからない((Copilotは書き換えて構わないみたいなことを言いますが…))ので、リストを作り直しそこに詰め込んで返しています。\\
-引数で貰った IEnumerable<CodeInstruction> を書き換えて返していいのかがわからないので、リストを作り直しそこに詰め込んで返しています。\\+
  
 <code csharp> <code csharp>
  • appendix/harmonyがある時.1734502895.txt.gz
  • 最終更新: 2024/12/18 15:21
  • by fumble