Jump to content

How do I insert an element to a list with a harmony transpiler patch?


Recommended Posts

Anyone adept in harmony transpiler patches? I want to insert a new tier level between bronze and iron, so the progression goes ... -> tin/bismuth bronze -> black bronze -> iron -> ....
The relevant jsons have been patched (changing miningTiers and toolTiers) and working fine. But I need to add the tier to a list in GetPlacedBlockInfo (in Block class):
image.png.362222272b843391475e1e7e598eb5de.png so the code becomes -> image.png.7aab77dd901368b9b36d65f352d902eb.png

So I thought it would be nice to accomplish this with a small transpiler patch. But I'm unsure how to go about this. Studying the IL-code for the list

Spoiler
	/* 0x000001D5 1D           */ IL_01D5: ldc.i4.7
	/* 0x000001D6 8D????????   */ IL_01D6: newarr    [System.Private.CoreLib]System.String
	/* 0x000001DB 25           */ IL_01DB: dup
	/* 0x000001DC 16           */ IL_01DC: ldc.i4.0
	/* 0x000001DD 72????????   */ IL_01DD: ldstr     "tier_hands"
	/* 0x000001E2 28????????   */ IL_01E2: call      !!0[] [System.Private.CoreLib]System.Array::Empty<object>()
	/* 0x000001E7 286C080006   */ IL_01E7: call      string Vintagestory.API.Config.Lang::Get(string, object[])
	/* 0x000001EC A2           */ IL_01EC: stelem.ref
	/* 0x000001ED 25           */ IL_01ED: dup
	/* 0x000001EE 17           */ IL_01EE: ldc.i4.1
	/* 0x000001EF 72????????   */ IL_01EF: ldstr     "tier_stone"
	/* 0x000001F4 28????????   */ IL_01F4: call      !!0[] [System.Private.CoreLib]System.Array::Empty<object>()
	/* 0x000001F9 286C080006   */ IL_01F9: call      string Vintagestory.API.Config.Lang::Get(string, object[])
	/* 0x000001FE A2           */ IL_01FE: stelem.ref
	/* 0x000001FF 25           */ IL_01FF: dup
	/* 0x00000200 18           */ IL_0200: ldc.i4.2
	/* 0x00000201 72????????   */ IL_0201: ldstr     "tier_copper"
	/* 0x00000206 28????????   */ IL_0206: call      !!0[] [System.Private.CoreLib]System.Array::Empty<object>()
	/* 0x0000020B 286C080006   */ IL_020B: call      string Vintagestory.API.Config.Lang::Get(string, object[])
	/* 0x00000210 A2           */ IL_0210: stelem.ref
	/* 0x00000211 25           */ IL_0211: dup
	/* 0x00000212 19           */ IL_0212: ldc.i4.3
	/* 0x00000213 72????????   */ IL_0213: ldstr     "tier_bronze"
	/* 0x00000218 28????????   */ IL_0218: call      !!0[] [System.Private.CoreLib]System.Array::Empty<object>()
	/* 0x0000021D 286C080006   */ IL_021D: call      string Vintagestory.API.Config.Lang::Get(string, object[])
	/* 0x00000222 A2           */ IL_0222: stelem.ref
	/* 0x00000223 25           */ IL_0223: dup
	/* 0x00000224 1A           */ IL_0224: ldc.i4.4
	/* 0x00000225 72????????   */ IL_0225: ldstr     "tier_iron"
	/* 0x0000022A 28????????   */ IL_022A: call      !!0[] [System.Private.CoreLib]System.Array::Empty<object>()
	/* 0x0000022F 286C080006   */ IL_022F: call      string Vintagestory.API.Config.Lang::Get(string, object[])
	/* 0x00000234 A2           */ IL_0234: stelem.ref
	/* 0x00000235 25           */ IL_0235: dup
	/* 0x00000236 1B           */ IL_0236: ldc.i4.5
	/* 0x00000237 72????????   */ IL_0237: ldstr     "tier_steel"
	/* 0x0000023C 28????????   */ IL_023C: call      !!0[] [System.Private.CoreLib]System.Array::Empty<object>()
	/* 0x00000241 286C080006   */ IL_0241: call      string Vintagestory.API.Config.Lang::Get(string, object[])
	/* 0x00000246 A2           */ IL_0246: stelem.ref
	/* 0x00000247 25           */ IL_0247: dup
	/* 0x00000248 1C           */ IL_0248: ldc.i4.6
	/* 0x00000249 72????????   */ IL_0249: ldstr     "tier_titanium"
	/* 0x0000024E 28????????   */ IL_024E: call      !!0[] [System.Private.CoreLib]System.Array::Empty<object>()
	/* 0x00000253 286C080006   */ IL_0253: call      string Vintagestory.API.Config.Lang::Get(string, object[])
	/* 0x00000258 A2           */ IL_0258: stelem.ref
	/* 0x00000259 1307         */ IL_0259: stloc.s   tiers

 

I get the feeling I can't just insert my code before IL_0225: ldstr     "tier_iron", since this would mess up the indexing, right? In that case, I would need to replace each subsequent ldc.i4.x instruction with x+1? Or must I replace all the IL-code for the entire list? If so, how do I replace this list? By replacing each instruction with a nop and then adding all the code again, including the new index?

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.