Worm Pseudo Code

offset NPC36

#define
grab = mov ecx,
grab2 = mov edx,
SETPTR = MOV EAX,[EBP+8]
SETPTR2 = MOV EDX,[EBP+8]
SETPARENT = MOV EAX,[EDX+A8]
in-use = [EAX]
collision = [EAX+4]
my.x = [EAX+8]
my.y = [EAX+C]
x-velo = [EAX+10]
y-velo = [EAX+14]
old.x = [EAX+18]
old.y = [EAX+1C]
my.type = [eax+28]
hp = [EAX+40]
event = [EAX+30]
direction = [EAX+4C]
frame-timer = [EAX+64]
frame = [EAX+68]
ObjTimer = [EAX+6C]
state = [EAX+74]
ScrTimer = [EAX+78]
damage = [EAX+A4]
QuoteX = [49E654]
QuoteY = [49E658]

#enddefine
push ebp
mov ebp, esp
sub esp, 10
SETPTR
grab state
JMP [EcX*4+:switchst8]

:State0
	cmp x-velo, 0
	jne :AA
	mov state, 1
	mov Damage, 2
	add hp, 5
	mov ObjTimer, 64
	jmp :AB
	:AA
	SETPTR2
	SETPARENT
	grab direction ;Get parent's direction
	SETPTR
	mov direction, ecx
	SETPTR2
	SETPARENT
	grab event
	SETPTR
	mov event,ecx
	SETPTR2
	SETPARENT
	grab frame
	SETPTR
	add ecx, 1
	cmp ecx, 3
	jle :AC
	sub ecx, 4
	:AC
	mov frame, ecx
	mov state, 3
	SETPTR2
	SETPARENT
	grab ObjTimer
	SETPTR
	dec ecx
	mov ObjTimer, ecx
	cmp ecx, 0
	jle :State3
	:AB
	grab ObjTimer
	add ecx, 28
	push ecx
	grab [ebp+8]
	push ecx
	push 0
	push 1
	push 1
	grab my.y
	sub ecx, 1ee0
	push ecx
	grab my.x
	push ecx
	push 24
	CALL 46EFD0
	add esp, 20
	SETPTR
	cmp state, 3
	je :State3

:State1
	SETPTR
	grab direction
	JMP [EcX*4+:switchdirA]

	:DirA0
	grab collision
	and ecx, 8
	cmp ecx, 0
	je :A
	inc state
	:D
	grab my.x
	mov old.x, ecx
	grab my.y
	mov old.y, ecx
	mov ScrTimer, 0
	grab my.x
	cmp ecx, QuoteX
	jle :B
	mov direction, 1
	jmp :C
	:B
	mov direction, 3
	:C
	jmp :Move
	:A
	inc ScrTimer
	cmp ScrTimer, 20
	jg :D
	jmp :Move

	:DirA1
	grab collision
	and ecx, 1
	cmp ecx, 0
	je :A1
	inc state
	:D1
	grab my.x
	mov old.x, ecx
	grab my.y
	mov old.y, ecx
	mov ScrTimer, 0
	grab my.y
	cmp ecx, QuoteY
	jle :B1
	mov direction, 2
	jmp :C1
	:B1
	mov direction, 0
	:C1
	jmp :Move
	:A1
	inc ScrTimer
	cmp ScrTimer, 20
	jg :D1
	jmp :Move

	:DirA2
	grab collision
	and ecx, 2
	cmp ecx, 0
	je :A2
	inc state
	:D2
	grab my.x
	mov old.x, ecx
	grab my.y
	mov old.y, ecx
	mov ScrTimer, 0
	grab my.x
	cmp ecx, QuoteX
	jle :B2
	mov direction, 1
	jmp :C2
	:B2
	mov direction, 3
	:C2
	jmp :Move
	:A2
	inc ScrTimer
	cmp ScrTimer, 20
	jg :D
	jmp :Move

	:DirA3
	grab collision
	and ecx, 4
	cmp ecx, 0
	je :A3
	inc state
	:D3
	grab my.x
	mov old.x, ecx
	grab my.y
	mov old.y, ecx
	mov ScrTimer, 0
	grab my.y
	cmp ecx, QuoteY
	jle :B3
	mov direction, 2
	jmp :C3
	:B3
	mov direction, 0
	:C3
	jmp :Move
	:A3
	inc ScrTimer
	cmp ScrTimer, 20
	jg :D3
	jmp :Move

:State2
	SETPTR
	grab direction
	JMP [EcX*4+:switchdirB]

	:DirB0
	grab collision
	and ecx, 8
	je :A4
	mov direction, 2
	jmp :Move
	:A4
	inc ScrTimer
	dec state
	jmp :Move

	:DirB1
	grab collision
	and ecx, 1
	je :A5
	mov direction, 3
	jmp :Move
	:A5
	inc ScrTimer
	dec state
	jmp :Move

	:DirB2
	grab collision
	and ecx, 2
	je :A6
	mov direction, 0
	jmp :Move
	:A6
	inc ScrTimer
	dec state
	jmp :Move

	:DirB3
	grab collision
	and ecx, 4
	je :A7
	mov direction, 1
	jmp :Move
	:A7
	inc ScrTimer
	dec state
	jmp :Move

:State3
	SETPTR2
	SETPARENT
	grab state
	SETPTR
	cmp ecx, 5
	jne :H
	sub state, 2
	mov ScrTimer, 64
	mov Damage, 2
	add hp, 5
	jmp :State1
	:H
	SETPTR2
	SETPARENT
	grab direction
	SETPTR
	cmp direction, ecx
	je :E
	inc state
	jmp :Move
	:E
	SETPTR
	grab direction
	JMP [EcX*4+:switchdirC]

	:DirC0
	SETPTR2
	SETPARENT
	grab my.y
	SETPTR
	sub ecx, 1ee0
	cmp my.y, ecx
	jge :Frame
	mov my.y, ecx
	jmp :Frame

	:DirC1
	SETPTR2
	SETPARENT
	grab my.x
	SETPTR
	add ecx, 1ee0
	cmp my.x, ecx
	jle :Frame
	mov my.x, ecx
	jmp :Frame

	:DirC2
	SETPTR2
	SETPARENT
	grab my.y
	SETPTR
	add ecx, 1ee0
	cmp my.y, ecx
	jle :Frame
	mov my.y, ecx
	jmp :Frame

	:DirC3
	SETPTR2
	SETPARENT
	grab my.x
	SETPTR
	sub ecx, 1ee0
	cmp my.x, ecx
	jge :Frame
	mov my.x, ecx
	jmp :Frame

:State4
	SETPTR2
	SETPARENT
	grab state
	SETPTR
	cmp ecx, 5
	jne :I
	sub state, 3
	mov ScrTimer, 64
	mov Damage, 2
	add hp, 5
	jmp :State1
	:I
	SETPTR
	grab direction
	JMP [EcX*4+:switchdirD]

:DirD0
	SETPTR2
	SETPARENT
	grab old.y
	SETPTR
	cmp my.y, ecx
	jl :Move
	grab my.x
	mov old.x, ecx
	grab my.y
	mov old.y, ecx
	SETPTR2
	SETPARENT
	grab my.x
	SETPTR
	cmp my.x, ecx
	jle :F
	mov direction, 1
	jmp :G
:F
	mov direction, 3
:G
	dec state
	jmp :Move

:DirD1
	SETPTR2
	SETPARENT
	grab old.x
	SETPTR
	cmp my.x, ecx
	jg :Move
	grab my.x
	mov old.x, ecx
	grab my.y
	mov old.y, ecx
	SETPTR2
	SETPARENT
	grab my.y
	SETPTR
	cmp my.y, ecx
	jle :F1
	mov direction, 2
	jmp :G1
:F1
	mov direction, 0
:G1
	dec state
	jmp :Move

:DirD2
	SETPTR2
	SETPARENT
	grab old.y
	SETPTR
	cmp my.y, ecx
	jg :Move
	grab my.x
	mov old.x, ecx
	grab my.y
	mov old.y, ecx
	SETPTR2
	SETPARENT
	grab my.x
	SETPTR
	cmp my.x, ecx
	jle :F2
	mov direction, 1
	jmp :G2
:F2
	mov direction, 3
:G2
	dec state
	jmp :Move

:DirD3
	SETPTR2
	SETPARENT
	grab old.x
	SETPTR
	cmp my.x, ecx
	jl :Move
	grab my.x
	mov old.x, ecx
	grab my.y
	mov old.y, ecx
	SETPTR2
	SETPARENT
	grab my.y
	SETPTR
	cmp my.y, ecx
	jle :F3
	mov direction, 2
	jmp :G3
:F3
	mov direction, 0
:G3
	dec state
	jmp :Move

:State5 ;Death
	xor ecx,ecx
	mov edx, my.type
	mov my.type, 9a
	mov state, ecx
	mov frame, ecx
	push edx
	call 470490
	add esp, 4
	cmp eax, 1
	je :END
	SETPTR
	grab event
	push ecx
	call 421990
	add esp, 4
	jmp :END

:Move
	SETPTR
	grab direction
	JMP [EcX*4+:switchdirE]

:DirE0
	add my.y, 260
	jmp :Frame

:DirE1
	sub my.x, 260
	jmp :Frame

:DirE2
	sub my.y, 260
	jmp :Frame

:DirE3
	add my.x, 260
	jmp :Frame

:Frame
cmp hp, 3cf
jge :BA
mov state, 5
:BA
add frame-timer, 1
cmp frame-timer, 4
jle :BC
mov frame-timer, 0
add frame, 1
cmp frame, 3
jle :BC
mov frame, 0
:BC
grab frame
imul ecx, ecx, 18
grab2 state
cmp edx, 3
je :BD
and edx, 3
cmp edx, 0
je :BD
add ecx, 60
:BD
mov [ebp-10], ecx
add ecx, 18
mov [ebp-8], ecx
grab direction
imul ecx, ecx, 18
mov [ebp-C], ecx
add ecx, 18
mov [ebp-4], ecx
SETPTR
add eax, 54
grab [ebp-10]
mov [eax], ecx
grab [ebp-c]
mov [eax+4], ecx
grab [ebp-8]
mov [eax+8], ecx
grab [ebp-4]
mov [eax+c], ecx

:END
mov esp, ebp
pop ebp
retn

:switchst8
print :State0
print :State1
print :State2
print :State3
print :State4
print :State5
:switchdirA
print :DirA0
print :DirA1
print :DirA2
print :DirA3
:switchdirB
print :DirB0
print :DirB1
print :DirB2
print :DirB3
:switchdirC
print :DirC0
print :DirC1
print :DirC2
print :DirC3
:switchdirD
print :DirD0
print :DirD1
print :DirD2
print :DirD3
:switchdirE
print :DirE0
print :DirE1
print :DirE2
print :DirE3

One response to “Worm Pseudo Code

  1. Pingback: Worm’s den « WTF Story progress & updates.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s