Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with new @ByRef Object[] #3

Closed
daviscook477 opened this issue Feb 13, 2018 · 3 comments
Closed

Bug with new @ByRef Object[] #3

daviscook477 opened this issue Feb 13, 2018 · 3 comments

Comments

@daviscook477
Copy link
Contributor

Patch

package basemod.patches.com.megacrit.cardcrawl.core.CardCrawlGame;

import com.evacipated.cardcrawl.modthespire.lib.ByRef;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;

import basemod.BaseMod;

@SpirePatch(cls="com.megacrit.cardcrawl.core.CardCrawlGame", method="createCharacter")
public class CreateCharacterSwitch {

	@SpireInsertPatch(loc=999, localvars={"p"})
	public static void Insert(Object selectionObj, @ByRef Object[] pObj) {
		AbstractPlayer.PlayerClass selection = (AbstractPlayer.PlayerClass) selectionObj;
		AbstractPlayer p = (AbstractPlayer) pObj[0];
		if (!selection.toString().equals("IRONCLAD") && !selection.toString().equals("THE_SILENT") &&
				!selection.toString().equals("CROWBOT")) {
			p = BaseMod.createCharacter(selection.toString(), CardCrawlGame.playerName);
			//pObj[0] = (Object) p;
		}
	}
	
}

Error Log

Compiling patched classes...
  com.megacrit.cardcrawl.shop.ShopScreen
  com.megacrit.cardcrawl.helpers.RelicLibrary
  com.megacrit.cardcrawl.credits.CreditsScreen
  com.megacrit.cardcrawl.rooms.CampfireUI
  com.megacrit.cardcrawl.core.EnergyManager
  com.megacrit.cardcrawl.ui.panels.TopPanel
  com.megacrit.cardcrawl.helpers.CardLibrary
  com.megacrit.cardcrawl.core.CardCrawlGame
  com.megacrit.cardcrawl.screens.mainMenu.MainMenuScreen
  com.badlogic.gdx.backends.lwjgl.LwjglApplication
  com.megacrit.cardcrawl.characters.AbstractPlayer
  com.megacrit.cardcrawl.dungeons.AbstractDungeon
Done.
Patching enums...Done.
Setting isModded = true...Done.
Adding ModTheSpire to version...
Exception in thread "Thread-2" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    com/megacrit/cardcrawl/core/CardCrawlGame.createCharacter(Lcom/megacrit/cardcrawl/characters/AbstractPlayer$PlayerClass;)Lcom/megacrit/cardcrawl/characters/AbstractPlayer; @106: getfield
  Reason:
    Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'com/megacrit/cardcrawl/characters/AbstractPlayer'
  Current Frame:
    bci: @106
    flags: { }
    locals: { 'com/megacrit/cardcrawl/characters/AbstractPlayer$PlayerClass', 'java/lang/Object', top, top, '[Ljava/lang/Object;' }
    stack: { 'java/lang/Object' }
  Bytecode:
    0x0000000: 014c b202 122a b602 132e aa00 0000 004a
    0x0000010: 0000 0001 0000 0003 0000 001a 0000 002b
    0x0000020: 0000 003c bb01 5559 b200 24b2 0157 b701
    0x0000030: 584c a700 22bb 0214 59b2 0024 b202 15b7
    0x0000040: 0216 4ca7 0011 bb02 1759 b200 24b2 0218
    0x0000050: b702 194c 04bd 0244 5903 2b53 3a04 2a19
    0x0000060: 04b8 071b 1904 0332 4c2b b401 0fb4 0110
    0x0000070: b600 d04d 2cb9 00a1 0100 9900 172c b900
    0x0000080: a201 00c0 0111 4e2d b401 14b8 021a a7ff
    0x0000090: e62b b0                                
  Stackmap Table:
    append_frame(@36,Null)
    same_frame(@53)
    same_frame(@70)
    full_frame(@84,{Object[#635],Object[#1058]},{})
    full_frame(@116,{Object[#635],Object[#580],Object[#952],Top,Object[#1821]},{})
    same_frame(@145)

	at java.lang.Class.getDeclaredFields0(Native Method)
	at java.lang.Class.privateGetDeclaredFields(Unknown Source)
	at java.lang.Class.getDeclaredField(Unknown Source)
	at com.evacipated.cardcrawl.modthespire.Loader.runMods(Loader.java:100)
	at com.evacipated.cardcrawl.modthespire.ModSelectWindow.lambda$null$0(ModSelectWindow.java:83)
	at java.lang.Thread.run(Unknown Source)
@daviscook477
Copy link
Contributor Author

Note that if I change the code to the following it works

package basemod.patches.com.megacrit.cardcrawl.core.CardCrawlGame;

import com.evacipated.cardcrawl.modthespire.lib.ByRef;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;

import basemod.BaseMod;

@SpirePatch(cls="com.megacrit.cardcrawl.core.CardCrawlGame", method="createCharacter")
public class CreateCharacterSwitch {

	@SpireInsertPatch(loc=999, localvars={"p"})
	public static void Insert(Object selectionObj, Object pObj) {
		AbstractPlayer.PlayerClass selection = (AbstractPlayer.PlayerClass) selectionObj;
		AbstractPlayer p = (AbstractPlayer) pObj;
		if (!selection.toString().equals("IRONCLAD") && !selection.toString().equals("THE_SILENT") &&
				!selection.toString().equals("CROWBOT")) {
			p = BaseMod.createCharacter(selection.toString(), CardCrawlGame.playerName);
			//pObj[0] = (Object) p;
		}
	}
	
}

@daviscook477
Copy link
Contributor Author

The issue is in the line src += info.localvars()[i] + " = __" + info.localvars()[i] + "[0];\n"; because it is trying to assign type Object to whatever type the localvar is without a type cast. A type cast is required to make this work. However, types cannot be obtained from local variables so the @ByRef annotation will need a field for allowing the modder to provide the fully qualified path of the type of the local variable

@kiooeht
Copy link
Owner

kiooeht commented Feb 13, 2018

Fixed in commit fbc476f

@kiooeht kiooeht closed this as completed Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants