Scriptname CCO_StartScript extends Quest  

bool property DLC1Loaded auto hidden			;Dawnguard
GlobalVariable property CCO_DLCDawnguard auto
GlobalVariable property MCM_CCODawnguardInst auto
bool property DLC2Loaded auto hidden			;Hearthfire
GlobalVariable property CCO_DLCHearthfire auto
GlobalVariable property MCM_CCOHearthfireInst auto
bool property DLC3Loaded auto hidden			;Dragonborn
GlobalVariable property CCO_DLCDragonborn auto
GlobalVariable property MCM_CCODragonbornInst auto

bool property USKPLoaded auto hidden			;Unofficial Skyrim Patch
GlobalVariable property CCO_ModUSKPInst auto
bool property UDGPLoaded auto hidden			;Unofficial Dawnguard Patch
GlobalVariable property CCO_ModUDGPInst auto
bool property UDBPLoaded auto hidden			;Unofficial Dragonborn Patch
GlobalVariable property CCO_ModUDBPInst auto

bool property MOD01Loaded auto hidden			;Stealth Skills Rebalanced - Complete
bool property MOD02Loaded auto hidden			;Stealth Skills Rebalanced - Lockpicking
GlobalVariable property CCO_MODStealthSkillsRebalanced auto

bool property MOD03Loaded auto hidden			;Immersive Armors
GlobalVariable property MCM_CCOImmersiveArmorsInst auto		

bool property MOD04Loaded auto hidden			;Frostfall
GlobalVariable property MCM_CCOFrostfallInst auto

bool property MOD05Loaded auto hidden			;Heavy Armory
GlobalVariable property MCM_CCOHeavyArmoryInst auto

bool property MOD06Loaded auto hidden			;Book of Silence
GlobalVariable property MCM_CCOBookofSilenceInst auto

bool property MOD07Loaded auto hidden			;Winter Is Coming
GlobalVariable property MCM_CCOWinterIsComingInst auto
GlobalVariable property	CCO_MODWICRequireBasket auto

bool property MOD08Loaded auto hidden			;Cloaks
GlobalVariable property MCM_CCOCloaksInst auto
GlobalVariable property	CCO_MODCloaksRequireBook auto
GlobalVariable property	CCO_MODCloaksBookDistChance auto

GlobalVariable property CCO_OptionArtifactReplicas auto
GlobalVariable property CCO_OptionArmoredCirclets auto
GlobalVariable property CCO_OptionCraftDaedricOnlyAtNight auto
GlobalVariable property CCO_DisableIfCCOisInstalled auto
GlobalVariable property CCO_LearningEnabled auto

CCO_CompatibilityScript Property CCO_MCMStartupQuest auto
Perk property CCO_EnchantingTweaks_Clothing auto
Perk property CCO_EnchantingTweaks_HandsHeadFeet auto
Perk property CCO_EnchantingTweaks_Jewelry auto
Perk property CCO_EnchantingTweaks_JewelryExpensive auto
Perk property CCO_EnchantingTweaks_JewelryExquisite auto
Perk property CCO_EnchantingTweaks_Torso auto
Perk property CCO_EnchantingTweaks_WeaponBow auto
Perk property CCO_EnchantingTweaks_WeaponDagger auto
Perk property CCO_EnchantingTweaks_WeaponOneHand auto
Perk property CCO_EnchantingTweaks_WeaponTwoHand auto
Perk property CCO_TemperTweaks_ArmorCuirass auto
Perk property CCO_TemperTweaks_ArmorGauntlets auto
Perk property CCO_TemperTweaks_ArmorLeatherFurHide auto
Perk property CCO_TemperTweaks_ArmorLight auto
Perk property CCO_TemperTweaks_ArmorShield auto
Perk property CCO_TemperTweaks_WeaponBow auto
Perk property CCO_TemperTweaks_WeaponDagger auto
Perk property CCO_TemperTweaks_WeaponTwoHand auto
Perk property CCO_TemperTweaks_Baseline auto


Event OnInit()
	RunModCheck()
	CCO_OptionArtifactReplicas.SetValue(0)
	CCO_OptionArmoredCirclets.SetValue(0)
	CCO_OptionCraftDaedricOnlyAtNight.SetValue(1)
	CCO_DisableIfCCOisInstalled.SetValue(0)
	CCO_LearningEnabled.SetValue(1)
	Actor PlayerRef = Game.getPlayer()
	PlayerRef.addperk(CCO_EnchantingTweaks_Clothing)
	PlayerRef.addperk(CCO_EnchantingTweaks_HandsHeadFeet)
	PlayerRef.addperk(CCO_EnchantingTweaks_Jewelry)
	PlayerRef.addperk(CCO_EnchantingTweaks_JewelryExpensive)
	PlayerRef.addperk(CCO_EnchantingTweaks_JewelryExquisite)
	PlayerRef.addperk(CCO_EnchantingTweaks_Torso)
	PlayerRef.addperk(CCO_EnchantingTweaks_WeaponBow)
	PlayerRef.addperk(CCO_EnchantingTweaks_WeaponDagger)
	PlayerRef.addperk(CCO_EnchantingTweaks_WeaponOneHand)
	PlayerRef.addperk(CCO_EnchantingTweaks_WeaponTwoHand)
	PlayerRef.addperk(CCO_TemperTweaks_ArmorCuirass)
	PlayerRef.addperk(CCO_TemperTweaks_ArmorGauntlets)
	PlayerRef.addperk(CCO_TemperTweaks_ArmorLeatherFurHide)
	PlayerRef.addperk(CCO_TemperTweaks_ArmorLight)
	PlayerRef.addperk(CCO_TemperTweaks_ArmorShield)
	PlayerRef.addperk(CCO_TemperTweaks_WeaponBow)
	PlayerRef.addperk(CCO_TemperTweaks_WeaponDagger)
	PlayerRef.addperk(CCO_TemperTweaks_WeaponTwoHand)
	PlayerRef.addperk(CCO_TemperTweaks_Baseline)
endEvent

function RunModCheck()
	if DLC1Loaded
		DLC1Loaded = Game.GetFormFromFile(0x020176F4, "Dawnguard.esm")
		if !DLC1Loaded			;Dawnguard was removed.
			CCO_DLCDawnguard.SetValue(0)
			MCM_CCODawnguardInst.SetValue(0)
		else
			CCO_DLCDawnguard.SetValue(1)
			MCM_CCODawnguardInst.SetValue(1)
		endif
	else
		DLC1Loaded = Game.GetFormFromFile(0x020176F4, "Dawnguard.esm")
		if DLC1Loaded			;Dawnguard has been added.
			CCO_DLCDawnguard.SetValue(1)
			MCM_CCODawnguardInst.SetValue(1)
		else
			CCO_DLCDawnguard.SetValue(0)
			MCM_CCODawnguardInst.SetValue(0)
		endif
	endif
	if DLC2Loaded
		DLC2Loaded = Game.GetFormFromFile(0x0200303f, "Hearthfires.esm")
		if !DLC2Loaded			;Hearthfire was removed.
			CCO_DLCHearthfire.SetValue(0)
			MCM_CCOHearthfireInst.SetValue(0)
		else
			CCO_DLCHearthfire.SetValue(1)
			MCM_CCOHearthfireInst.SetValue(1)
		endif
	else
		DLC2Loaded = Game.GetFormFromFile(0x0200303f, "Hearthfires.esm")
		if DLC2Loaded			;Hearthfire has been added.
			CCO_DLCHearthfire.SetValue(1)
			MCM_CCOHearthfireInst.SetValue(1)
		else
			CCO_DLCHearthfire.SetValue(0)
			MCM_CCOHearthfireInst.SetValue(0)
		endif
	endif
	if DLC3Loaded
		DLC3Loaded = Game.GetFormFromFile(0x02037b8c, "Dragonborn.esm")
		if !DLC3Loaded			;Dragonborn was removed.
			CCO_DLCDragonborn.SetValue(0)
			MCM_CCODragonbornInst.SetValue(0)
		else
			CCO_DLCDragonborn.SetValue(1)
			MCM_CCODragonbornInst.SetValue(1)
		endif
	else
		DLC3Loaded = Game.GetFormFromFile(0x02037b8c, "Dragonborn.esm")
		if DLC3Loaded			;Dragonborn has been added.
			CCO_DLCDragonborn.SetValue(1)
			MCM_CCODragonbornInst.SetValue(1)
		else
			CCO_DLCDragonborn.SetValue(0)
			MCM_CCODragonbornInst.SetValue(0)
		endif
	endif
	if USKPLoaded
		USKPLoaded = Game.GetFormFromFile(0x0200080B, "Unofficial Skyrim Patch.esp")
		if !USKPLoaded			;USKP was removed.
			CCO_ModUSKPInst.SetValue(0)
		else
			CCO_ModUSKPInst.SetValue(1)
		endif
	else
		USKPLoaded = Game.GetFormFromFile(0x0200080B, "Unofficial Skyrim Patch.esp")
		if USKPLoaded			;USKP has been added.
			CCO_ModUSKPInst.SetValue(1)
			CCO_MCMStartupQuest.USKPCompatibility()
		else
			CCO_ModUSKPInst.SetValue(0)
		endif
	endif
	if UDGPLoaded
		UDGPLoaded = Game.GetFormFromFile(0x020273B1, "Unofficial Dawnguard Patch.esp")
		if !UDGPLoaded			;UDGP was removed.
			CCO_ModUDGPInst.SetValue(0)
		else
			CCO_ModUDGPInst.SetValue(1)
		endif
	else
		UDGPLoaded = Game.GetFormFromFile(0x020273B1, "Unofficial Dawnguard Patch.esp")
		if UDGPLoaded			;UDGP has been added.
			CCO_ModUDGPInst.SetValue(1)
			CCO_MCMStartupQuest.UDGPCompatibility()
		else
			CCO_ModUDGPInst.SetValue(0)
		endif
	endif
	if UDBPLoaded
		UDBPLoaded = Game.GetFormFromFile(0x02056633, "Unofficial Dragonborn Patch.esp")
		if !UDBPLoaded			;UDBP was removed.
			CCO_ModUDBPInst.SetValue(0)
		else
			CCO_ModUDBPInst.SetValue(1)
		endif
	else
		UDBPLoaded = Game.GetFormFromFile(0x020273B1, "Unofficial Dragonborn Patch.esp")
		if UDBPLoaded			;UDBP has been added.
			CCO_ModUDBPInst.SetValue(1)
			CCO_MCMStartupQuest.UDBPCompatibility()
		else
			CCO_ModUDBPInst.SetValue(0)
		endif
	endif
	
	if MOD01Loaded
		MOD01Loaded = Game.GetFormFromFile(0x02000D62, "Stealth Skills Rebalanced_COMPLETE.esp")
		if !MOD01Loaded			;Stealth Skills Rebalanced was removed.
			CCO_MODStealthSkillsRebalanced.SetValue(0)
		else
			CCO_MODStealthSkillsRebalanced.SetValue(1)
		endif
	else
		MOD01Loaded = Game.GetFormFromFile(0x02000D62, "Stealth Skills Rebalanced_COMPLETE.esp")
		if MOD01Loaded				;Stealth Skills Rebalanced has been added.
			CCO_MODStealthSkillsRebalanced.SetValue(1)
		else
			CCO_MODStealthSkillsRebalanced.SetValue(0)
		endif
	endif
	if MOD02Loaded
		MOD02Loaded = Game.GetFormFromFile(0x02000D62, "Stealth Skills Rebalanced_LOCKPICKING.esp")
		if !MOD02Loaded			;Stealth Skills Rebalanced was removed.
			CCO_MODStealthSkillsRebalanced.SetValue(0)
		else
			CCO_MODStealthSkillsRebalanced.SetValue(1)
		endif
	else
		MOD02Loaded = Game.GetFormFromFile(0x02000D62, "Stealth Skills Rebalanced_LOCKPICKING.esp")
		if MOD02Loaded				;Stealth Skills Rebalanced has been added.
			CCO_MODStealthSkillsRebalanced.SetValue(1)
		else
			CCO_MODStealthSkillsRebalanced.SetValue(0)
		endif
	endif
	if MOD03Loaded
		MOD03Loaded = Game.GetFormFromFile(0x020238E6, "Hothtrooper44_ArmorCompilation.esp")
		if !MOD03Loaded				;Immersive Armors was removed.
			MCM_CCOImmersiveArmorsInst.SetValue(0)
		else
			MCM_CCOImmersiveArmorsInst.SetValue(1)
		endif
	else
		MOD03Loaded = Game.GetFormFromFile(0x020238E6, "Hothtrooper44_ArmorCompilation.esp")
		if MOD03Loaded				;Immersive Armors has been added.
			MCM_CCOImmersiveArmorsInst.SetValue(1)
		else
			MCM_CCOImmersiveArmorsInst.SetValue(0)
		endif
	endif
	if MOD04Loaded
		MOD04Loaded = Game.GetFormFromFile(0x0201A31D, "Chesko_Frostfall.esp")
		if !MOD04Loaded				;Frostfall was removed.
			MCM_CCOFrostfallInst.SetValue(0)
		else
			MCM_CCOFrostfallInst.SetValue(1)
		endif
	else
		MOD04Loaded = Game.GetFormFromFile(0x0201A31D, "Chesko_Frostfall.esp")
		if MOD04Loaded				;Frostfall has been added.
			MCM_CCOFrostfallInst.SetValue(1)
		else
			MCM_CCOFrostfallInst.SetValue(0)
		endif
	endif
	if MOD05Loaded
		MOD05Loaded = Game.GetFormFromFile(0x0204EF93, "PrvtI_HeavyArmory.esp")
		if !MOD05Loaded				;Heavy Armory was removed.
			MCM_CCOHeavyArmoryInst.SetValue(0)
		else
			MCM_CCOHeavyArmoryInst.SetValue(1)
		endif
	else
		MOD05Loaded = Game.GetFormFromFile(0x0204EF93, "PrvtI_HeavyArmory.esp")
		if MOD05Loaded				;Heavy Armory has been added.
			MCM_CCOHeavyArmoryInst.SetValue(1)
		else
			MCM_CCOHeavyArmoryInst.SetValue(0)
		endif
	endif
	if MOD06Loaded
		MOD06Loaded = Game.GetFormFromFile(0x02000D6F, "aMidianborn_Book of Silence_CCO.esp")
		if !MOD06Loaded				;Book of Silence was removed.
			MCM_CCOBookofSilenceInst.SetValue(0)
		else
			MCM_CCOBookofSilenceInst.SetValue(1)
		endif
	else
		MOD06Loaded = Game.GetFormFromFile(0x02000D6F, "aMidianborn_Book of Silence_CCO.esp")
		if MOD06Loaded				;Book of Silence has been added.
			MCM_CCOBookofSilenceInst.SetValue(1)
		else
			MCM_CCOBookofSilenceInst.SetValue(0)
		endif
	endif
	if MOD07Loaded
		MOD07Loaded = Game.GetFormFromFile(0x0200233C, "1nivWICCloaks.esp") || Game.GetFormFromFile(0x0200233C, "1nivWICCloaksCRAFT.esp") || Game.GetFormFromFile(0x0200233C, "1nivWICCloaksNoGuards.esp")
		if !MOD07Loaded				;Winter Is Coming was removed.
			MCM_CCOWinterIsComingInst.SetValue(0)
		else
			MCM_CCOWinterIsComingInst.SetValue(1)
		endif
	else
		MOD07Loaded = Game.GetFormFromFile(0x0200233C, "1nivWICCloaks.esp") || Game.GetFormFromFile(0x0200233C, "1nivWICCloaksCRAFT.esp") || Game.GetFormFromFile(0x0200233C, "1nivWICCloaksNoGuards.esp")
		if MOD07Loaded				;Winter Is Coming has been added.
			MCM_CCOWinterIsComingInst.SetValue(1)
			CCO_MODWICRequireBasket.setValue(0) 
		else
			MCM_CCOWinterIsComingInst.SetValue(0)
		endif
	endif
	if MOD08Loaded
		MOD08Loaded = Game.GetFormFromFile(0x0201A8DF, "Cloaks.esp") || Game.GetFormFromFile(0x0201A8DF, "Cloaks - No Imperial.esp") || Game.GetFormFromFile(0x0201A8DF, "Cloaks - Player Only.esp") 
		if !MOD08Loaded				;Cloaks of Skyrim was removed.
			MCM_CCOCloaksInst.SetValue(0)
		else
			MCM_CCOCloaksInst.SetValue(1)
		endif
	else
		MOD08Loaded = Game.GetFormFromFile(0x0201A8DF, "Cloaks.esp") || Game.GetFormFromFile(0x0201A8DF, "Cloaks - No Imperial.esp") || Game.GetFormFromFile(0x0201A8DF, "Cloaks - Player Only.esp") 
		if MOD08Loaded				;Cloaks of Skyrim has been added.
			MCM_CCOCloaksInst.SetValue(1)
			CCO_MODCloaksRequireBook.setValue(0) 
			CCO_MODCloaksBookDistChance.setValue(100)
		else
			MCM_CCOCloaksInst.SetValue(0)
		endif		
	endif
endFunction




