SMALI File Structure
📌Key components
Class Reference
Super Class
Annotations
Static Fields
Instance Fields
Direct Methods
Virtual Methods
📍Example code
.class public Lde/fgerbig/spacepeng/components/Player;
.super Lcom/artemis/Component;
.source "Player.java"
# annotations
.annotation build Lcom/artemis/annotations/PooledWeaver;
.end annotation
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lde/fgerbig/spacepeng/components/Player$State;
}
.end annotation
# static fields
.field public static final DEFAULT_LIVES:I = 0x3e7
.field public static final SPRITE_NAME:Ljava/lang/String; = "player"
.field public static final SPRITE_NAME_SHIELD:Ljava/lang/String; = "playershield"
# instance fields
.field public lives:I
.field public score:I
.field private state:Lde/fgerbig/spacepeng/components/Player$State;
# direct methods
.method public constructor <init>()V
.locals 1
.prologue
.line 24
invoke-direct {p0}, Lcom/artemis/Component;-><init>()V
.line 37
sget-object v0, Lde/fgerbig/spacepeng/components/Player$State;->ALIVE:Lde/fgerbig/spacepeng/components/Player$State;
iput-object v0, p0, Lde/fgerbig/spacepeng/components/Player;->state:Lde/fgerbig/spacepeng/components/Player$State;
.line 39
const v0, 0x3e7
iput v0, p0, Lde/fgerbig/spacepeng/components/Player;->lives:I
return-void
.end method
# virtual methods
.method public isState(Lde/fgerbig/spacepeng/components/Player$State;)Z
.locals 1
.param p1, "state" # Lde/fgerbig/spacepeng/components/Player$State;
.prologue
.line 47
iget-object v0, p0, Lde/fgerbig/spacepeng/components/Player;->state:Lde/fgerbig/spacepeng/components/Player$State;
invoke-virtual {v0, p1}, Lde/fgerbig/spacepeng/components/Player$State;->equals(Ljava/lang/Object;)Z
move-result v0
return v0
.end method
.method public setState(Lde/fgerbig/spacepeng/components/Player$State;)V
.locals 0
.param p1, "state" # Lde/fgerbig/spacepeng/components/Player$State;
.prologue
.line 43
iput-object p1, p0, Lde/fgerbig/spacepeng/components/Player;->state:Lde/fgerbig/spacepeng/components/Player$State;
.line 44
return-void
.end method
📍Here's a breakdown of the code
Class Definition
.class public Lde/fgerbig/spacepeng/components/Player; .super Lcom/artemis/Component; .source "Player.java"
public
class: Declares a public class namedPlayer
.Superclass: Inherits from
Lcom/artemis/Component
, indicating the class belongs to a component-based architecture.Source file: The Java source file is
Player.java
.
Annotations
Annotations provide metadata to the Android runtime or tools:
.annotation build Lcom/artemis/annotations/PooledWeaver; .end annotation
PooledWeaver
: Likely an annotation for component pooling in the Artemis entity framework, improving memory efficiency.
.annotation system Ldalvik/annotation/MemberClasses; value = { Lde/fgerbig/spacepeng/components/Player$State; } .end annotation
MemberClasses
: Declares an inner class calledState
insidePlayer
.
Static Fields
Static fields are shared across all instances of the class:
.field public static final DEFAULT_LIVES:I = 0x3e7
DEFAULT_LIVES
: A constant integer initialized to0x3e7
(hexadecimal for999
)
.field public static final SPRITE_NAME:Ljava/lang/String; = "player" .field public static final SPRITE_NAME_SHIELD:Ljava/lang/String; = "playershield"
SPRITE_NAME
: String constant"player"
.SPRITE_NAME_SHIELD
: String constant"playershield"
.
Instance Fields
Instance fields belong to specific objects of the class:
.field public lives:I .field public score:I .field private state:Lde/fgerbig/spacepeng/components/Player$State;
lives
: Public integer field representing the player's lives.score
: Public integer field for the player's score.state
: A private reference to the inner classPlayer$State
.
Direct Methods
Direct methods include constructors and private/static methods.
Constructor
.method public constructor <init>()V .locals 1 .prologue .line 24 invoke-direct {p0}, Lcom/artemis/Component;-><init>()V
<init>()
: Constructor for the class.invoke-direct
: Calls the superclass (Component
) constructor.
.line 37 sget-object v0, Lde/fgerbig/spacepeng/components/Player$State;->ALIVE:Lde/fgerbig/spacepeng/components/Player$State; iput-object v0, p0, Lde/fgerbig/spacepeng/components/Player;->state:Lde/fgerbig/spacepeng/components/Player$State;
sget-object
: Retrieves the static valueALIVE
from the inner classPlayer$State
.iput-object
: Assigns theALIVE
state to thestate
field.
.line 39 const v0, 0x3e7 iput v0, p0, Lde/fgerbig/spacepeng/components/Player;->lives:I
Initializes the
lives
field to999
(0x3e7
in hex).
Virtual Methods
Virtual methods can be overridden by subclasses.
isState Method
.method public isState(Lde/fgerbig/spacepeng/components/Player$State;)Z .locals 1 .param p1, "state" # Lde/fgerbig/spacepeng/components/Player$State;
isState
: Checks if the player's state matches the given state.
iget-object v0, p0, Lde/fgerbig/spacepeng/components/Player;->state:Lde/fgerbig/spacepeng/components/Player$State; invoke-virtual {v0, p1}, Lde/fgerbig/spacepeng/components/Player$State;->equals(Ljava/lang/Object;)Z
iget-object
: Loads the currentstate
field intov0
.invoke-virtual
: Calls theequals
method on thestate
to compare it with the parameterp1
.
move-result v0 return v0 .end method
Returns the result of the comparison (
true
orfalse
).
Last updated