User File #63940818881263633

Upload All User Files

#63940818881263633 - Red Alert script

Command & Conquer - Red Alert (USA) (Disc 2) (Soviet).lua
344 downloads
Uploaded 6/10/2020 1:49 PM by lapogne36 (see all 25)
Command & Conquer: Red Alert script to display various data on screen (didn't test it for the Allies disc but it should work fine for it too)


--Xrange 3456
--Yrange 2592



-- 0x2A780 nb vehicles
-- 0x2A3BC nb enemy vehicles
-- 0x8023C nb enemy infantry ?

-- 0x2A578 Player
-- 0x2A1B4 Computer
-- 0x29DF0 Other

--Border of the screen with gui.drawText standard
local XMIN = 80
local XMAX = 722
local YMIN = -8
local YMAX = 470

local NBENT
local ADENT
local DATASIZE
local ENTDATA
local DISPLAY
local VTYPE
local RIFLE
local ROCKET
local DOG
local RANGER
local LIGHT
local MEDIUM
local TRUCK
local STRUCTURE

local X, Y

local ENT_NAME = {			   --Entity name (1 or 2 letters = infantry)
"","","","","","","","","","", --000
"","","","","","","","","","", --010
"","","","","","","","","","", --020
"","","","","","","","","","", --030
"","","","","","","","","","", --040
"","","light","heavy","medium","mammoth","SAM","ranger","chinook","truck", --050
"art.","R","G","Ro","F","longbow","hind","APC","dome","helipad", --060
"airfield","silo","constr","ore ref","civ","civ","civ","civ","civ","civ", --070
"civ","civ","civ","civ","civ","civ","civ","civ","civ","civ", --080
"civ","civ","","civ","civ","civ","civ","civ","civ","civ", --090
"civ","civ","civ","civ","civ","civ","civ","civ","civ","civ", --100
"civ","tech","tur","MCV","plant","plant+","hospital","barracks","civ","sand", --110
"chain","wall","barb","wood","factory","biolab","depot","","","", --120
"","","","","","","","","","", --130
"","","C","C","C","C","C","C","C","C", --140
"C","Ei","","","","","","","","", --150
"","","","","","","","","","", --160
"","","","","","","","","","", --170
"","","","","","","","","","", --180
"","","","","","","","","","", --190
"","","","","","","","","","", --200
"","","","","","","","","","", --210
"","","","","","","","","","", --220
"","","","","","","","","","", --230
"","","","","","","","","E","S", --240
"","","","","","","","C","","", --250
"","","","","","","","","","", --260
"","","","C","","","","","","", --270
"","","","","","","","","","", --280
"","","","","","","","","","", --290
"","mine","mine","","T","jammer","gap","pill","pill+","chrono", --300
"","","","","","","","","","", --310
"sub","destr","cruiser","transp","boat","","","","","", --320
"","","","","","tesla","mobile","flame","AA","kennel", --330
"tech","bomber","mig","yak","barb","M","Ge","T","","", --340
"naval","pen","","","plane","D","","","","", --350
"supply","","iron","tech","V2R","forward","layer","fake","fake","fake", --360
"fake","fake","","","","","","","","", --370
"","","","","","","","","","", --380
"","","","","bar","","","","","", --390
"","missile","","","","","","","","" --400
}

local X_AJUST = {    --X size of the entity
0,0,0,0,0,0,0,0,0,0, --000
0,0,0,0,0,0,0,0,0,0, --010
0,0,0,0,0,0,0,0,0,0, --020
0,0,0,0,0,0,0,0,0,0, --030
0,0,0,0,0,0,0,0,0,0, --040
0,0,1,1,1,1,1,1,1,1, --050
1,1,1,1,1,1,1,0,2,2, --060
3,1,3,3,2,1,1,2,1,2, --070
1,1,1,1,1,1,1,1,1,1, --080
1,1,0,1,1,1,1,1,1,1, --090
1,1,1,1,1,1,1,1,1,1, --100
1,3,1,1,2,3,0,2,1,1, --110
1,1,1,1,3,0,3,0,0,0, --120
0,0,0,0,0,0,0,0,0,0, --130
0,0,1,1,1,1,1,1,1,1, --140
1,1,0,0,0,0,0,0,0,0, --150
0,0,0,0,0,0,0,0,0,0, --160
0,0,0,0,0,0,0,0,0,0, --170
0,0,0,0,0,0,0,0,0,0, --180
0,0,0,0,0,0,0,0,0,0, --190
0,0,0,0,0,0,0,0,0,0, --200
0,0,0,0,0,0,0,0,0,0, --210
0,0,0,0,0,0,0,0,0,0, --220
0,0,0,0,0,0,0,0,0,0, --230
0,0,0,0,0,0,0,0,1,1, --240
0,0,0,0,0,0,0,1,0,0, --250
0,0,0,0,0,0,0,0,0,0, --260
0,0,0,1,0,0,0,0,0,0, --270
0,0,0,0,0,0,0,0,0,0, --280
0,0,0,0,0,0,0,0,0,0, --290
0,1,1,0,1,1,1,1,1,2, --300
0,0,0,0,0,0,0,0,0,0, --310
1,1,1,2,1,0,0,0,0,0, --320
0,0,0,0,0,1,1,1,1,1, --330
3,0,1,1,1,1,1,1,0,0, --340
0,0,0,0,0,1,1,0,0,0, --350
1,0,2,3,1,2,1,0,0,0, --360
0,0,0,0,0,0,0,0,0,0, --370
0,0,0,0,0,0,0,0,0,0, --380
0,0,0,0,1,0,0,0,0,0, --390
0,2,0,0,0,0,0,0,0,0 --400
}

local Y_AJUST = {    --Y size of the entity
0,0,0,0,0,0,0,0,0,0, --000
0,0,0,0,0,0,0,0,0,0, --010
0,0,0,0,0,0,0,0,0,0, --020
0,0,0,0,0,0,0,0,0,0, --030
0,0,0,0,0,0,0,0,0,0, --040
0,0,1,1,1,1,1,1,1,1, --050
1,1,1,1,1,1,1,0,3,3, --060
2,1,3,4,3,1,1,3,1,1, --070
1,1,1,1,1,1,1,1,1,1, --080
1,1,0,1,1,1,1,1,1,1, --090
1,1,1,1,1,1,1,1,1,1, --100
1,3,1,1,2,3,0,3,1,1, --110
1,1,1,1,3,0,3,0,0,0, --120
0,0,0,0,0,0,0,0,0,0, --130
0,0,1,1,1,1,1,1,1,1, --140
1,1,0,0,0,0,0,0,0,0, --150
0,0,0,0,0,0,0,0,0,0, --160
0,0,0,0,0,0,0,0,0,0, --170
0,0,0,0,0,0,0,0,0,0, --180
0,0,0,0,0,0,0,0,0,0, --190
0,0,0,0,0,0,0,0,0,0, --200
0,0,0,0,0,0,0,0,0,0, --210
0,0,0,0,0,0,0,0,0,0, --220
0,0,0,0,0,0,0,0,0,0, --230
0,0,0,0,0,0,0,0,1,1, --240
0,0,0,0,0,0,0,1,0,0, --250
0,0,0,0,0,0,0,0,0,0, --260
0,0,0,1,0,0,0,0,0,0, --270
0,0,0,0,0,0,0,0,0,0, --280
0,0,0,0,0,0,0,0,0,0, --290
0,1,1,0,1,1,1,1,1,2, --300
0,0,0,0,0,0,0,0,0,0, --310
1,1,1,2,1,0,0,0,0,0, --320
0,0,0,0,0,1,1,1,1,1, --330
3,0,1,1,1,1,1,1,0,0, --340
0,0,0,0,0,1,1,0,0,0, --350
1,0,2,3,1,2,1,0,0,0, --360
0,0,0,0,0,0,0,0,0,0, --370
0,0,0,0,0,0,0,0,0,0, --380
0,0,0,0,1,0,0,0,0,0, --390
0,2,0,0,0,0,0,0,0,0 --400
}

while true do

	local X1 = memory.read_s16_le(0x1BBAAC)
	local X2 = math.abs(memory.read_s16_le(0x1B3964))
	local XF = X1+X2*256/24								--X coordinate at the top left of the screen
	
	local Y1 = memory.read_s16_le(0x1BBAAE)
	local Y2 = memory.read_s16_le(0x1BBAA8)
	local YF = Y1+Y2*256/24								--Y coordinate at the top left of the screen
	
	-- local XSIZE = memory.read_u8(0x16BAFC) --Total X size of the map
	-- local YSIZE = memory.read_u8(0x16BB00) --Total Y size of the map

	gui.drawText(1, 80, math.floor(XF), "white")
	gui.drawText(1, 100, math.floor(YF), "white")
	
	gui.drawText(1, 140, memory.read_u8(0x2A3BC), "white")
	gui.drawText(1, 160, memory.read_u8(0x8023C), "white")
	
	if XF>0 then
	
		RIFLE = 0
		ROCKET = 0
		DOG = 0
		RANGER = 0
		LIGHT = 0
		MEDIUM = 0
		TRUCK = 0
		STRUCTURE = 0

		-----------------------------------------Vehicles-------------------------------------------
		-- ENTDATA = 0x87578	--Where the data starts in the RAM
		
		DATASIZE = 0x108	--Size of the data of one entity
		NBENT = memory.read_u32_le(0x9776C) --Number of entites followed by their data addresses
		
		if NBENT>0 and NBENT<251 and memory.read_u32_le(0x9776C + 0x4)>0x80000000 then
			for i=1, NBENT do
			
				ADENT = memory.read_u32_le(0x9776C + i*0x4) - 0x80000000
				
				if memory.read_u32_le(ADENT + 0x14)>0x8009E000 and memory.read_u32_le(ADENT + 0x14)<0x800A5000 then
				
					ENT_NUM = math.min(memory.read_u16_le(memory.read_u32_le(ADENT + 0x14) - 0x80000000 + 0x2), 410)

					DISPLAY = memory.read_s16_le(ADENT+0x1E) -- HP
					-- DISPLAY = string.format("%05X", ADENT) -- Address
					-- DISPLAY = string.format("%08X", memory.read_u32_le(ADENT+0x7C)) -- Owner
					-- DISPLAY = string.format("%08X", memory.read_u32_le(ADENT+0x14)) -- Address ID
					-- DISPLAY = ENT_NAME[ENT_NUM] -- Name
					
					X = memory.read_s16_le(ADENT) + 32*X_AJUST[ENT_NUM]
					Y = memory.read_s16_le(ADENT+0x2) + 32*Y_AJUST[ENT_NUM]
					
					VTYPE = memory.read_u32_le(ADENT+0x14)
					
					if VTYPE==0x800A45D0 then 
						-- DISPLAY = memory.read_u8(ADENT+0x105) -- Ore cargo display
						-- COLOR = "red"
						gui.drawText(
							XMIN + (X-XF)/3456*(XMAX-XMIN), 
							YMIN + (Y-YF)/2592*(YMAX-YMIN) + 15, 
							memory.read_u8(ADENT+0x105),
							"red",
							null,null,null,null,"center"
						)
					end
					
					if memory.read_u32_le(ADENT+0x7C)==0x8002A1B4 then 
						if VTYPE==0x800A4564 then RANGER = RANGER + 1
						elseif VTYPE==0x800A4420 then LIGHT = LIGHT + 1
						elseif VTYPE==0x800A43B4 then MEDIUM = MEDIUM + 1
						elseif VTYPE==0x800A45D0 then TRUCK = TRUCK + 1
						end
					end

					if X>XF and X<(XF+3456) and Y>YF and Y<(YF+2592) then

						gui.drawText(
						XMIN + (X-XF)/3456*(XMAX-XMIN), 
						YMIN + (Y-YF)/2592*(YMAX-YMIN), 
						DISPLAY,
						"white",
						null,null,null,null,"center")

					end
				
				end

			end
		end
		
		-----------------------------------------Infantry-------------------------------------------
		-- ENTDATA = 0x2DA94
		
		DATASIZE = 0xF0	--Size of the data of one entity
		NBENT = memory.read_u32_le(0x3C518) --Number of entites followed by their data addresses
		
		if NBENT>0 and NBENT<251 and memory.read_u32_le(0x3C518 + 0x4)>0x80000000 then
			for i=1, NBENT do
			
				ADENT = memory.read_u32_le(0x3C518 + i*0x4) - 0x80000000
				
				if memory.read_u32_le(ADENT + 0x14)>0x8009E000 and memory.read_u32_le(ADENT + 0x14)<0x800A5000 then
				
					ENT_NUM = math.min(memory.read_u16_le(memory.read_u32_le(ADENT + 0x14) - 0x80000000 + 0x2), 410)
					
					DISPLAY = memory.read_s16_le(ADENT+0x1E) -- HP
					-- DISPLAY = string.format("%05X", ADENT) -- Address
					-- DISPLAY = string.format("%08X", memory.read_u32_le(ADENT+0x7C)) -- Owner
					-- DISPLAY = ENT_NAME[ENT_NUM] -- Name
					
					X = memory.read_s16_le(ADENT) + 32*X_AJUST[ENT_NUM]
					Y = memory.read_s16_le(ADENT+0x2) + 32*Y_AJUST[ENT_NUM]
		
					VTYPE = memory.read_u32_le(ADENT+0x14)
					
					if memory.read_u32_le(ADENT+0x7C)==0x8002A1B4 then 
						if VTYPE==0x800A227C then RIFLE = RIFLE + 1
						elseif VTYPE==0x800A235C then ROCKET = ROCKET + 1
						elseif VTYPE==0x800A26DC then DOG = DOG + 1
						end
					end

					if X>XF and X<(XF+3456) and Y>YF and Y<(YF+2592) then

						gui.drawText(
						XMIN + (X-XF)/3456*(XMAX-XMIN), 
						YMIN + (Y-YF)/2592*(YMAX-YMIN), 
						DISPLAY, 
						"white",
						null,null,null,null,"center")

					end
				
				end

			end
		end
		
		-----------------------------------------Aircrafts-------------------------------------------
		-- ENTDATA = 0x14B7C
		
		DATASIZE = 0xF8	--Size of the data of one entity
		NBENT = memory.read_u32_le(0x1AC70) --Number of entites followed by their data addresses
		
		if NBENT>0 and NBENT<101 and memory.read_u32_le(0x1AC70 + 0x4)>0x80000000 then
			for i=1, NBENT do
				
				ADENT = memory.read_u32_le(0x1AC70 + i*0x4) - 0x80000000
				
				if memory.read_u32_le(ADENT + 0x14)>0x8009E000 and memory.read_u32_le(ADENT + 0x14)<0x800A5000 then
				
					ENT_NUM = math.min(memory.read_u16_le(memory.read_u32_le(ADENT + 0x14) - 0x80000000 + 0x2), 410)
					
					DISPLAY = memory.read_s16_le(ADENT+0x1E) -- HP
					-- DISPLAY = string.format("%05X", ADENT)
					-- DISPLAY = string.format("%08X", memory.read_u32_le(ADENT+0x14)) -- Address ID
					-- DISPLAY = ENT_NAME[ENT_NUM] -- Name
				
					X = memory.read_s16_le(ADENT) + 32*X_AJUST[ENT_NUM]
					Y = memory.read_s16_le(ADENT+0x2) + 32*Y_AJUST[ENT_NUM] - memory.read_s16_le(ADENT+0x8)

					if X>XF and X<(XF+3456) and Y>YF and Y<(YF+2592) then

						gui.drawText(
						XMIN + (X-XF)/3456*(XMAX-XMIN), 
						YMIN + (Y-YF)/2592*(YMAX-YMIN), 
						DISPLAY,
						"white",
						null,null,null,null,"center")

					end
				
				end
				
			end
			
		end
		
		-----------------------------------------Buildings-------------------------------------------
		-- ENTDATA = 0x1AE20 --0x1C74C
		
		DATASIZE = 0xC4	--Size of the data of one entity
		NBENT = memory.read_u32_le(0x286D8) --Number of entites followed by their data addresses
		
		if NBENT>0 and NBENT<251 and memory.read_u32_le(0x286D8 + 0x4)>0x80000000 then
			for i=1, NBENT do
			
				ADENT = memory.read_u32_le(0x286D8 + i*0x4) - 0x80000000
				
				if memory.read_u32_le(ADENT + 0x14)>0x8009E000 and memory.read_u32_le(ADENT + 0x14)<0x800A5000 then
				
					ENT_NUM = math.min(memory.read_u16_le(memory.read_u32_le(ADENT + 0x14) - 0x80000000 + 0x2), 410)
					
					DISPLAY = memory.read_s16_le(ADENT+0x1E) -- HP
					-- DISPLAY = string.format("%05X", ADENT) -- Address
					-- DISPLAY = string.format("%08X", memory.read_u32_le(ADENT+0x7C)) -- Owner
					-- DISPLAY = string.format("%08X", memory.read_u32_le(ADENT+0x14)) -- Address ID
					-- DISPLAY = ENT_NAME[ENT_NUM] -- Name
					
					X = memory.read_s16_le(ADENT) + 40 + 128*X_AJUST[ENT_NUM]
					Y = memory.read_s16_le(ADENT+0x2) + 128*Y_AJUST[ENT_NUM]
						
					if memory.read_u32_le(ADENT+0x7C)==0x8002A1B4 then 
						STRUCTURE = STRUCTURE + 1
					end
						
					if X>XF and X<(XF+3456) and Y>YF and Y<(YF+2592) then

						gui.drawText(
						XMIN + (X-XF)/3456*(XMAX-XMIN), 
						YMIN + (Y-YF)/2592*(YMAX-YMIN), 
						DISPLAY,
						"white",
						null,null,null,null,"center")

					end
				
				end

			end
		end
		
		-----------------------------------------Ore-------------------------------------------------
		--Limiting the check to the current screen, i.e. 12x15 grid instead of 128x128
		local iMIN = math.floor(YF/256)
		local jMIN = math.floor(XF/256)
		
		local ORE = 0
		local COLOR = "white"
		
		for i=iMIN, iMIN+11 do
		
			for j=jMIN, jMIN+14 do
			
				X = 128 + j*256
				Y = 128 + i*256
				
				-- if i==86 and j==102 then
					-- gui.drawText(1, 160, string.format("%08X)0x40000 + j*16 + i*2048, "white")
				-- end
				
				-- if X>XF and X<(XF+3456) and Y>YF and Y<(YF+2592) then
				
					local BASE = 0x40000 + j*16 + i*2048
				
					--Is it an ore tile ?
					if memory.read_u8(BASE + 0xE) == 0x28 or memory.read_u8(BASE + 0xE) == 0x29 then
					
						local ORETYPE = memory.read_u8(BASE + 0xD) % 16
					
						--Is it normal ore ?
						if ORETYPE>=5 and ORETYPE<=8 then
							ORE = math.floor(memory.read_u8(BASE + 0xD)/32)
							if memory.read_u8(BASE + 0xE) == 0x29 then ORE = ORE + 8 end
							COLOR = "red"
						end
						
						--Is it special ore ?
						if ORETYPE>=9 and ORETYPE<=0xC then
							ORE = math.floor(memory.read_u8(BASE + 0xD)/32)*4 + 3
							if memory.read_u8(BASE + 0xE) == 0x29 then ORE = ORE + 16 end
							COLOR = "blue"
						end
						
						gui.drawText(
						XMIN + (X-XF)/3456*(XMAX-XMIN), 
						YMIN + (Y-YF)/2592*(YMAX-YMIN), 
						ORE, 
						COLOR)
				
					end
				
				end
			
			-- end
			
		end
	
		gui.drawText(1, 200, "Rifle : " .. RIFLE, "white")
		gui.drawText(1, 220, "Rocket : " .. ROCKET, "white")
		gui.drawText(1, 240, "Dog : " .. DOG, "white")
		gui.drawText(1, 260, "Ranger : " .. RANGER, "white")
		gui.drawText(1, 280, "Light : " .. LIGHT, "white")
		gui.drawText(1, 300, "Medium : " .. MEDIUM, "white")
		gui.drawText(1, 320, "Truck : " .. TRUCK, "white")
		gui.drawText(1, 340, "Structure : " .. STRUCTURE, "white")
	
	end --if XF>0 then

	emu.frameadvance()

end