{$CLEO .cs}

/*
test:
	ACHIEVEMENT_09
	ACHIEVEMENT_10
	ACHIEVEMENT_11
	ACHIEVEMENT_12
	ACHIEVEMENT_13
	ACHIEVEMENT_15
	ACHIEVEMENT_16
	ACHIEVEMENT_22
	ACHIEVEMENT_23
	ACHIEVEMENT_24
*/

0001: wait 0 ms	

while true
    0001: wait 500 ms	


	// ACHIEVEMENT_01 - Unlock all trophies.
	05F5: call_scm_func @getIsAllTrophiesUnlocked 0 ret_to 1@
	if
		1@ == true
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 1
	end

	
	// ACHIEVEMENT_02 - Complete "Luigi's Girls".
	if 
		$245 == 1 // flag_luigi_mission1_passed
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 2
	end


	// ACHIEVEMENT_03 - Destroy five helicopters.
	05F5: call_scm_func @getHelisDestroyed 0 ret_to 0@
	if
		0@ >= 5
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 3
	end
	
	
	// ACHIEVEMENT_04 - Crush a car at the junkyard.
	05F5: call_scm_func @getCarsCrushed 0 ret_to 0@
	if
		0@ > 0
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 4
	end

	
	// ACHIEVEMENT_05 - Get busted 20 times.
	05F5: call_scm_func @getTimesArrested 0 ret_to 0@
	if
		0@ >= 20
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 5
	end
	

	// ACHIEVEMENT_06 - Waste 100 gang members.
	05F5: call_scm_func @getGangMemersWasted 0 ret_to 0@
	if
		0@ >= 100
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 6
	end
	
	
	// ACHIEVEMENT_07 - Waste 1,000 people.
	05F5: call_scm_func @getPeopleKilledByPlayer 0 ret_to 0@
	if
		0@ >= 1000
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 7
	end
	
	
	// ACHIEVEMENT_08 - Blow up 2,000 cars.
	05F5: call_scm_func @getCarsExploded 0 ret_to 0@
	if
		0@ >= 2000
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 8
	end
	
	
	// ACHIEVEMENT_09 - Complete the "Turismo" race in under 180 seconds.
	05F5: call_scm_func @getElBurroTime 0 ret_to 0@
	if and
		0@ <> 0
		0@ <= 180
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 9
	end
	

	// ACHIEVEMENT_10 - Perform a perfect insane stunt.
	05F5: call_scm_func @getIsStuntPerfect 0 ret_to 0@
	if
		0@ == 1
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 10
	end


	// ACHIEVEMENT_11 - Complete 20 unique jumps.
	if 
		$778 == 20 // total_completed_usj
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 11
	end
	
	
	// ACHIEVEMENT_12 - Complete "Patriot Playground", "A Ride in the Park", "Multi-Story Mayhem", and "Gripped!" missions.
	if and
		$378 == 1 // flag_4x4_mission1_passed - 4x4 by Far
		$379 == 1 // flag_4x4_mission2_passed - A ride in the Park
		$380 == 1 // flag_4x4_mission3_passed - GRIPPED, SORTED
		$381 == 1 // flag_mayhem_mission1_passed - Multi-storey Mayhem
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 12
	end
	
	
	// ACHIEVEMENT_13 - Complete 100 taxi fares.
	if
		$395 >= 100 // taxi_passed
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 13
	end
	

	// ACHIEVEMENT_14 - Pass all 20 Rampages.
	if 
		$841 == 20 // total_rampages_passed
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 14
	end
	
	
	// ACHIEVEMENT_15 - Complete the Portland Docks and Shoreside Vale import/export car lists.
	// CHECK
	if and
		$979 == 16 // suburban_garage_slots_filled
		$928 == 16 // industrial_garage_slots_filled
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 15
	end
	

	// ACHIEVEMENT_16 - Deliver all emergency vehicles to the crane at the Portland Docks.
	if
		03EC: ev_crane_collected_all_cars
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 16
	end

	
	// ACHIEVEMENT_17 - Complete "Last Requests".
	if 
		$271 == 1 // flag_frankie_mission4_passed
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 17
	end
	
	
	// ACHIEVEMENT_18 - Complete "A Drop in the Ocean".
	if 
		$337 == 1 // flag_love_mission3_passed
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 18
	end
	
	
	// ACHIEVEMENT_19 - Complete "The Exchange".
	if 
		$368 == 1 // flag_cat_mission1_passed
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 19
	end
	
	
	// ACHIEVEMENT_20 - Complete the "Kingdom Come" mission.
	if 
		$342 == 1 // flag_yardie_mission4_passed
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 20
	end
	
	
	// ACHIEVEMENT_21 - Complete every RC Toyz mission.
	if and
		$409 == 1 // flag_rc1_passed
		$410 == 1 // flag_rc2_passed
		$411 == 1 // flag_rc3_passed
		$412 == 1 // flag_rc4_passed
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 21
	end
	
	
	// ACHIEVEMENT_22 - Extinguish 20 fires during a single Fire Truck mission.
	if
		$1371 >= 20 // fires_extinguished
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 22
	end
	
	
	// ACHIEVEMENT_23 - Complete Paramedic level 12.
	if
		$1295 >= 13 // ambulance_level
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 23
	end

	
	// ACHIEVEMENT_24 - Kill 20 criminals during one Vigilante mission.
	if
		$1409 >= 20 // total_criminals_killed
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 24
	end
	

	// ACHIEVEMENT_25 - Amass a fortune of $1,000,000.
	if
		010A:   player $PLAYER_CHAR money > 999999
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 25
	end

	
	// ACHIEVEMENT_26 - Earn a criminal rating of 2,500.
	05F5: call_scm_func @getCriminalRating 0 ret_to 0@
	if
		0@ >= 2500
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 26
	end

	
	// ACHIEVEMENT_27 - Earn a criminal rating of 5,000 or higher.
	if
		0@ >= 5000
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 27
	end
	

	// ACHIEVEMENT_28 - Collect 100 hidden packages.
	if
		$1043 == 100 // number_of_packages_collected
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 28
	end
	

	// ACHIEVEMENT_29 - Achieve 100% completion.
	05F5: call_scm_func @getProgressInGame 0 ret_to 0@
	if
		0@ == 100
	then
		0667: SET_ACHIEVEMENT_UNLOCKED 29
	end	
	
	// testing stuff

	// 01E3: text_1number_styled 'REWARD' 1@ 6000 ms 6 
	
	//for 1@ = 1 to 29
	//	0666: SET_ACHIEVEMENT 1@ true
	//end
end




//-----------------------------------------------------------------------------------
:AddressByVersion
{
	05F5: call_scm_func @AddressByVersion 3 _1_0 0x00 _1_1 0x00 _steam 0x00 ret_to 1@
}

05E5: 3@ = game_version
if
    3@ == 0 // V1_0
then
    05F6: ret 1 0@
end

if
    3@ == 1 // V1_1
then
    05F6: ret 1 1@
end

if
    3@ == 2 // VSTEAM
then
    05F6: ret 1 2@
end

if
    3@ == 3 // VSTEAMENC
then
    05F6: ret 1 2@
end

//-----------------------------------------------------------------------------------
:getArrayElement
{
	05F5: call_scm_func @getArrayElement 3 array_addr 0x00 sizeof_element 0x00 element 0 ret_to 1@
}
const
    // Parameters
	array_addr = 0@
	sizeof_element = 1@
    element = 2@
	// Variables
    result = 3@
end
var
	0@: int
	1@: int
	2@: int
	3@: int
end

3@ = 2@
3@ *= 1@
3@ += 0@
05F6: ret 1 3@

//-----------------------------------------------------------------------------------
:getIsAllTrophiesUnlocked
{
	05F5: call_scm_func @getIsAllTrophiesUnlocked 0 ret_to 1@
}
const
    // Parameters
	// 
	// Variables
    result = 0@
end
var
	0@: int
end

0@ = false

for 1@ = 2 to 29
	if
		0668: IS_ACHIEVEMENT_UNLOCKED 1@
	then
		0@ = true
	else
		05F6: ret 1 false
	end
end

05F6: ret 1 0@

//-----------------------------------------------------------------------------------
:getHelisDestroyed
{
	05F5: call_scm_func @getHelisDestroyed 0 ret_to 1@
}
const
    // Parameters
	// 
	// Variables
    result = 0@
end
var
	0@: int
end

05F5: call_scm_func @AddressByVersion 3 _1_0 0x8E2A64 _1_1 0x8E2A14 _steam 0x8F2B54 ret_to 0@
05E0: 0@ = read_memory 0@ size 4 virtual_protect 0
05F6: ret 1 0@

//-----------------------------------------------------------------------------------
:getCarsCrushed
{
	05F5: call_scm_func @getCarsCrushed 0 ret_to 1@
}
const
    // Parameters
	// 
	// Variables
    result = 0@
end
var
	0@: int
end

05F5: call_scm_func @AddressByVersion 3 _1_0 0x943050 _1_1 0x943208 _steam 0x953348 ret_to 0@
05E0: 0@ = read_memory 0@ size 4 virtual_protect 0
05F6: ret 1 0@

//-----------------------------------------------------------------------------------
:getTimesArrested
{
	05F5: call_scm_func @getTimesArrested 0 ret_to 1@
}
const
    // Parameters
	// 
	// Variables
    result = 0@
end
var
	0@: int
end

05F5: call_scm_func @AddressByVersion 3 _1_0 0x8E2BEC _1_1 0x8E2CA0 _steam 0x8F2DE0 ret_to 0@
05E0: 0@ = read_memory 0@ size 4 virtual_protect 0
05F6: ret 1 0@

//-----------------------------------------------------------------------------------
:getGangMemersWasted
{
	05F5: call_scm_func @getGangMemersWasted 0 ret_to 1@
}
const
    // Parameters
	// 
	// Variables
    arrayStart = 0@
	temp1 = 1@
	temp2 = 2@
    result = 3@
end
var
	0@: int
	1@: int
	2@: int
	3@: int
end
		
05F5: call_scm_func @AddressByVersion 3 _1_0 0x880DBC _1_1 0x880D6C _steam 0x890EAC ret_to 0@
3@ = 0

for 4@ = 7 to 15
	05F5: call_scm_func @getArrayElement 3 0@ 4 4@ ret_to 1@
	05E0: 2@ = read_memory 1@ size 4 virtual_protect 0
	3@ += 2@
end

05F6: ret 1 3@

//-----------------------------------------------------------------------------------
:getPeopleKilledByPlayer
{
	05F5: call_scm_func @getPeopleKilledByPlayer 0 ret_to 1@
}
const
    // Parameters
	// 
	// Variables
    result = 0@
end
var
	0@: int
end

05F5: call_scm_func @AddressByVersion 3 _1_0 0x8F1B7C _1_1 0x8F1C30 _steam 0x901D70 ret_to 0@
05E0: 0@ = read_memory 0@ size 4 virtual_protect 0
05F6: ret 1 0@

//-----------------------------------------------------------------------------------
:getCarsExploded
{
	05F5: call_scm_func @getCarsExploded 0 ret_to 1@
}
const
    // Parameters
	// 
	// Variables
    result = 0@
end
var
	0@: int
end

05F5: call_scm_func @AddressByVersion 3 _1_0 0x941288 _1_1 0x941440 _steam 0x951580 ret_to 0@
05E0: 0@ = read_memory 0@ size 4 virtual_protect 0
05F6: ret 1 0@

//-----------------------------------------------------------------------------------
:getElBurroTime
{
	05F5: call_scm_func @getElBurroTime 0 ret_to 1@
}
const
    // Parameters
	// 
	// Variables
    result = 0@
end
var
	0@: int
end

05F5: call_scm_func @AddressByVersion 3 _1_0 0x8E2A6C _1_1 0x8E2B20 _steam 0x8F2C60 ret_to 0@
05E0: 0@ = read_memory 0@ size 4 virtual_protect 0
05F6: ret 1 0@

//-----------------------------------------------------------------------------------
:getIsStuntPerfect
{
	05F5: call_scm_func @getIsStuntPerfect 0 ret_to 1@
}
const
    // Parameters
	// 
	// Variables
    result = 0@
end
var
	0@: int
end

05F5: call_scm_func @AddressByVersion 3 _1_0 0x885B50 _1_1 0x885B00 _steam 0x895C40 ret_to 0@
05E0: 0@ = read_memory 0@ size 4 virtual_protect 0

if and
	$739 <> 0 // stunt_flags_hj
	$738 == 1 // flag_wheels_hj
then
	05F6: ret 1 1
else
	if
		0@ > 1
	then
		05F6: ret 1 1
	end
end

05F6: ret 1 0

//-----------------------------------------------------------------------------------
:getCriminalRating
{
	05F5: call_scm_func @getCriminalRating 0 ret_to 1@
}
const
    // Parameters
	// 
	// Variables
	func = 0@
    result = 1@
end
var
	0@: int
	1@: int
end

05F5: call_scm_func @AddressByVersion 3 _1_0 0x4AB2A0 _1_1 0x4AB390 _steam 0x4AB320 ret_to 0@
05E2: call_function 0@ num_params 0 pop 0 1@
05F6: ret 1 1@

//-----------------------------------------------------------------------------------
:getProgressInGame
{
	05F5: call_scm_func @getProgressInGame 0 ret_to 1@
}
const
    // Parameters
	// 
	// Variables
	totalProgressInGame = 0@
	progressMade = 1@
	v3 = 2@
    result = 3@
end
var
	0@: int
	1@: int
	2@: int
	3@: int
end

05F5: call_scm_func @AddressByVersion 3 _1_0 0x885B2C _1_1 0x885ADC _steam 0x895C1C ret_to 0@
05F5: call_scm_func @AddressByVersion 3 _1_0 0x8F6224 _1_1 0x8F63DC _steam 0x90651C ret_to 1@
05E0: 0@ = read_memory 0@ size 4 virtual_protect 0
05E0: 1@ = read_memory 1@ size 4 virtual_protect 0
	
if
    0@ <> 0
then
	if
		0351:   gore_enabled
	then
		2@ = 0@
	else
		2@ = 0@
		2@ -= 1
	end
	
	3@ = 1@
	3@ *= 100
	3@ /= 2@
else
    3@ = 0
end

if
    3@ > 100
then
    3@ = 100
end

05F6: ret 1 3@