User File #35549731585198412

Upload All User Files

#35549731585198412 - Crash 3 Lua script

Crash3_lapogne.lua
1118 downloads
Uploaded 12/9/2016 11:23 PM by lapogne36 (see all 25)
function toBits(num,bits)
    -- returns a table of bits, less significant first.
    bits = bits or select(2,math.frexp(num))
    local t={} -- will contain the bits        
    for b=1, bits do
        t[b]=math.fmod(num,2)
        num=(num-t[b])/2
    end
    return t
end

pScale = 1000 
vScale = 100000
Xold = 0
Yold = 0
Xorigin=-3
Yorigin=-922

CRYSTAL_ID={
" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";
"Lv03";"Lv01";"Lv04";"Lv18";"Lv02";"Lv06";"Lv11";"Lv10";"Lv09";"Lv17";
"Lv14";"Lv08";"Lv07";"Lv24";"Lv20";"Lv05";"Lv13";"Lv19";"Lv12";"Lv15";
"Lv16";"Lv30";"Lv22";"Lv26";"Lv23";"Lv21";"Lv25";"Lv28";"Lv32";"Lv31";
" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";
" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";" NA ";
" NA ";" NA ";" NA ";" NA "
}

--memory.write_u32_le(0x068FD8, 0xFFFFFFFF)
--memory.write_u32_le(0x06912C, 0xFFFFFFFF)

while true do

while true do

	--Crash pointer, checking that it is in RAM range
	local ADDR = memory.read_u32_le(0x60A90) - 0x80000000
	if math.abs(ADDR)>0x200000 then break end
	--gui.drawText(1,70,"pointer:","white")
	--gui.drawText(40,70,string.format("%8X",ADDR))
	
	-- Display Crash position and angle
	local X  = memory.read_s32_le( ADDR + 0x60 ) / pScale 
	local Y  = memory.read_s32_le( ADDR + 0x68 ) / pScale 
	local Z  = memory.read_s32_le( ADDR + 0x64 ) / pScale 
	local ANGLE  = math.floor(memory.read_u32_le( ADDR + 0x94 ) / 4096 * 360)
	gui.drawText(1,100,"X pos:","green")
	gui.drawText(1,115,"Y pos:","green")
	gui.drawText(1,130,"Z pos:","green")
	gui.drawText(1,145,"Angle:","green")
	gui.drawText(50,100,math.floor(X))
	gui.drawText(50,115,math.floor(Y))
	gui.drawText(50,130,math.floor(Z))
	gui.drawText(50,145,ANGLE)
	
	--Display Crash Speed and angle
	local XV = memory.read_s32_le( ADDR + 0x84 ) / vScale
	local YV = memory.read_s32_le( ADDR + 0x8C ) / vScale
	local ZV = (memory.read_s32_le( ADDR + 0x88 )+136533) / vScale 
	local XYV = math.floor(math.sqrt(XV*XV+YV*YV)*100000)/100000
	gui.drawText(1,175,"X vel:","red")
	gui.drawText(1,190,"Y vel:","red")
	gui.drawText(1,205,"Z vel:","red")
	gui.drawText(1,220,"XY vel:","red")
	gui.drawText(50,175,XV)
	gui.drawText(50,190,YV) 
	gui.drawText(50,205,math.floor(ZV*10)/10)
	gui.drawText(55,220,XYV)

	
	--Calculate the distance from a specific point
	DISTANCE=math.sqrt((X-Xorigin)^2+(Y-Yorigin)^2)
	--gui.drawText(1,280,math.floor(DISTANCE*100))
	
	--Jump Counter and Crystal Counter
	local BOX = memory.read_s16_le( ADDR + 0x1B5 )
	gui.drawText(1,250,"Jump Counter:","blue")
	gui.drawText(98,250,BOX)
	CRYSTAL_COUNTER = memory.read_s8( ADDR + 0x159 )
	gui.drawText(1,265,"Crystals:","blue")
	gui.drawText(70,265,CRYSTAL_COUNTER)
	
	--Overwrite Crash Speed (useful to find the perfect path)
	ANGLE2=350*(4096/360) --uncomment the 2 next lines to apply it
	--memory.write_s32_le(ADDR + 0x104, 2000000)
	--memory.write_s32_le(ADDR + 0x94, ANGLE2)
	
	--local Xspeed=-5000*vScale
	--local Yspeed=2000*vScale
	--memory.write_s32_le(ADDR + 0x84, Xspeed)
	--memory.write_s32_le(ADDR + 0x8C, Yspeed)
	
	--Compass
	local XCIRCLE, YCIRCLE, RADIUS = 72, 370, 60
	for i = 1, 720 do
		ANGLEDRAW = i * math.pi / 360
		local ptx, pty = XCIRCLE + RADIUS * math.cos( ANGLEDRAW ), YCIRCLE + RADIUS * math.sin( ANGLEDRAW )
		gui.drawPixel( ptx, pty )
	end
	ANGLEDRAW2 = (ANGLE * math.pi / 180) -- (math.pi / 2)
	gui.drawLine(XCIRCLE, YCIRCLE, XCIRCLE + 3 * XYV * math.sin(ANGLEDRAW2), YCIRCLE + 3 * XYV * math.cos(ANGLEDRAW2) )
	
	--Crystals Images
	RIGHT_SIDE = 0 --Put to 0 if you don't want to see the crystals on the right side
	if (RIGHT_SIDE==1) then
	CRYSTAL_LIST = memory.read_u32_le(0x068FD8)
	CRYSTAL_Y_N = toBits(CRYSTAL_LIST,32)
	CRYSTAL_LIST2 = memory.read_u32_le(0x06912C)
	CRYSTAL_Y_N2 = toBits(CRYSTAL_LIST2,32)
	for i=0, 5 do
		for j=0, 4 do
			id=i*5+j
			if (CRYSTAL_Y_N[id+1]==1 or CRYSTAL_Y_N2[id+1]==1) 
				then image = "D:/crash3/crystal2.gif"
				else image = "D:/crash3/crystal4.gif" 
			end
			gui.drawImage(image,660+j*29,80+i*60,20,30)
			gui.drawText(660+j*29,105+i*60,200+id,null,null,10)
			gui.drawText(657+j*29,115+i*60,CRYSTAL_ID[id+1],null,null,10)
			if (BOX==200+id) then
				gui.drawText(660+j*29,105+i*60,200+id,"red",null,10)
				--gui.drawEllipse(668+j*29,137+i*60,5,5,"purple","purple")
			end
		end
	end
	end
	
	emu.frameadvance()
	Xold = X
	Yold = Y
end

	emu.frameadvance()
end