SHADERMOD_VERSION = "|cFFFFFFFFv3.05";

DISPLAY_RED = ".55";	
DISPLAY_GREEN = ".55";
DISPLAY_BLUE = ".5"; 

FDISPLAY_RED = ".7";	
FDISPLAY_GREEN = ".1";
FDISPLAY_BLUE = ".1"; 

function SMOnLoad()

	this:RegisterEvent("VARIABLES_LOADED");
	this:RegisterEvent("CHAT_MSG_COMBAT_SELF_HITS");
	this:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE");
	this:RegisterEvent("CHAT_MSG_COMBAT_SELF_MISSES");
	this:RegisterEvent("PLAYER_ENTERING_WORLD");
	this:RegisterEvent("PLAYER_REGEN_ENABLED");
	this:RegisterEvent("UNIT_COMBO_POINTS");

	CritDmg = 0;
	CritCombo = 0;
	CritComboDmg = 0;
	CurrentSpell = 0;
      CritMsg = ".";

	SMMessageFrame:SetBackdropColor( 1.0, 1.0, 1.0, 0.0 );
      SMMessageFrame:SetBackdropBorderColor( 1.0, 1.0, 1.0, 0.0 );
      SMMessageFrameBackground:SetAlpha(0.0);
	SMMessageFrame:EnableMouse(false);							

	DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFSky-|cFF0000FFDexter. |cFF00FF00ShaderMod " .. SHADERMOD_VERSION .. " |cFFFF0000.:Loaded:. |cFFFFFFFF: /sm for options", .2, .0);
	
	SMPlayerRealm = GetCVar("realmName");
	SMPlayerName = UnitName("player");	
	
	UIPanelWindows["ShaderModOptionsFrame"] = {area = "center", pushable = 0};
end

function SMInitialize()
	SlashCmdList["CritCombo"] = SMCommand;
	SLASH_CritCombo1 = "/ShaderMod";
	SLASH_CritCombo2 = "/ShaderM";
	SLASH_CritCombo3 = "/sm"
	
	SMInitializeSMData();
	SMSetFontSizes();
end

function SMSetDefaultOptions()
	SMData[SMPlayerRealm][SMPlayerName].Reset_Combo = true;
	SMData[SMPlayerRealm][SMPlayerName].Party_Display = false;
	SMData[SMPlayerRealm][SMPlayerName].Raid_Display = false;
	SMData[SMPlayerRealm][SMPlayerName].Running_Crit_Display = true;
	SMData[SMPlayerRealm][SMPlayerName].Running_Hit_Display = true;
	SMData[SMPlayerRealm][SMPlayerName].Running_Combat_Log_Display = true;
	SMData[SMPlayerRealm][SMPlayerName].Running_Old_School_Display = false;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Finish_Him = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Yeah = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Oh_Yeah = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Unstoppable = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Killing_Spree = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Dominating = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Ultra_Kill = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Wicked_Sick = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_God_Like = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Holy_Shit = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Monster_Kill = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Ludicrous_Kill = true;
	SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Ownage = true;
	SMData[SMPlayerRealm][SMPlayerName].JustifyH_Left = true;													
	SMData[SMPlayerRealm][SMPlayerName].JustifyH_Center = false;
	SMData[SMPlayerRealm][SMPlayerName].JustifyH_Right = false;
	SMData[SMPlayerRealm][SMPlayerName].SMiniMapButton_Visible = true;
	SMData[SMPlayerRealm][SMPlayerName].SMiniMapButton_Locked = false;
end

SMSavedVars = { 
	SMFontSize = 30;
};

function getVar( varName)
	return SMSavedVars[varName];
end

function setVar( varName, value)
	SMSavedVars[varName] = value;
end

function SMFontSize_OnValueChanged()
	setVar("SMFontSize", this:GetValue());
	getglobal(this:GetName() .. "Text"):SetText(SM_FONT_SIZE .. " " .. this:GetValue());
	SMSetFontSizes();
end

function SMFontSize_OnShow()
	getglobal(this:GetName().."High"):SetText("32");
	getglobal(this:GetName().."Low"):SetText("8");

	this:SetMinMaxValues(8, 32);
	this:SetValueStep(1);
	this:SetValue(getVar("SMFontSize"));

	getglobal(this:GetName() .. "Text"):SetText(SM_FONT_SIZE .. " " .. this:GetValue());
end

function SMSetFontSizes()
	local font, fontHeight, flags = SMMessageFrame:GetFont();
 	SMMessageFrame:SetFont(font, getVar("SMFontSize"), flags);
end

function SMCommand(msg)
	if (string.lower(msg) == "records") then
		DEFAULT_CHAT_FRAME:AddMessage("[ShaderMod] " .. SHADERMOD_VERSION .. " ", .2, .0);
		DEFAULT_CHAT_FRAME:AddMessage("--- Hits Based Record ---", .65, .65, .6);
		DEFAULT_CHAT_FRAME:AddMessage("*" .. SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritCombo .. "* crits for *" .. SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritComboDmg .. "* damage. ");
		DEFAULT_CHAT_FRAME:AddMessage("--- Damage Based Record ---", .65, .65, .6);
		DEFAULT_CHAT_FRAME:AddMessage("*" .. SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritCombo .. "* crits for *" .. SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritComboDmg .. "* damage. ");
		return;
	end
	
	if (string.lower(msg) == "help") then
		SMDisplayHelp();
		return;
	end
	if (string.lower(msg) == "lock") then
		SMMessageFrame.Locked = true;
       	SMMessageFrame:SetBackdropColor( 1.0, 1.0, 1.0, 0.0 );
      	SMMessageFrame:SetBackdropBorderColor( 1.0, 1.0, 1.0, 0.0 );
       	SMMessageFrameBackground:SetAlpha(0.0);
		SMMessageFrame:EnableMouse(false);
		DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFSky-|cFF0000FFDexter. |cFF00FF00ShaderMod " .. SHADERMOD_VERSION .. " : |cFF00FF00Now |cFFFF0000Locked ", .2, .0);
	  return;
	end
	if (string.lower(msg) == "unlock") then
		SMMessageFrame.Locked = false;
        	SMMessageFrame:SetBackdropColor( 1.0, 1.0, 1.0, 1.0 );
        	SMMessageFrame:SetBackdropBorderColor( 1.0, 1.0, 1.0, 1.0 );
        	SMMessageFrameBackground:SetAlpha(1.0); 
		SMMessageFrame:EnableMouse(true);
		DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFSky-|cFF0000FFDexter. |cFF00FF00ShaderMod " .. SHADERMOD_VERSION .. " : |cFF00FF00Now |cFFFF0000Unlocked ", .2, .0);
	  return;
	end
	if (string.lower(msg) == "minimap lock") then
		SMData[SMPlayerRealm][SMPlayerName].SMiniMapButton_Locked = true;
		SMMiniMapButton.Locked = true;
		DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFSky-|cFF0000FFDexter. |cFF00FF00ShaderMod " .. SHADERMOD_VERSION .. " : MiniMap Button |cFF00FF00Now |cFFFF0000Locked ", .2, .0);
	  return;
	end
	if (string.lower(msg) == "minimap unlock") then
		SMData[SMPlayerRealm][SMPlayerName].SMiniMapButton_Locked = false;
		SMMiniMapButton.Locked = false;
		DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFSky-|cFF0000FFDexter. |cFF00FF00ShaderMod " .. SHADERMOD_VERSION .. " : MiniMap Button |cFFFF0000Unlocked ", .2, .0);
	  return;
	end
	if (string.lower(msg) == "hide") then
		SMMessageFrame.Visible = false;
		SMMessageFrame:Hide();
		DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFSky-|cFF0000FFDexter. |cFF00FF00ShaderMod " .. SHADERMOD_VERSION .. " : |cFF00FF00Now |cFFFF0000Hidden ", .2, .0);
	  return;
	end
	if (string.lower(msg) == "show") then
		SMMessageFrame.Visible = true;
		SMMessageFrame:Show();
		DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFSky-|cFF0000FFDexter. |cFF00FF00ShaderMod " .. SHADERMOD_VERSION .. " : |cFF00FF00Now |cFFFF0000Visible ", .2, .0);
	  return;
	end
	if (string.lower(msg) == "minimap show") then
		SMData[SMPlayerRealm][SMPlayerName].SMiniMapButton_Visible = true;
		SMMiniMapButton:Show();
		DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFSky-|cFF0000FFDexter. |cFF00FF00ShaderMod " .. SHADERMOD_VERSION .. " : MiniMap Button |cFF00FF00Now |cFFFF0000Visible ", .2, .0);
	  return;
	end
	if (string.lower(msg) == "minimap hide") then
		SMData[SMPlayerRealm][SMPlayerName].SMiniMapButton_Visible = false;
		SMMiniMapButton:Hide();
		DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFSky-|cFF0000FFDexter. |cFF00FF00ShaderMod " .. SHADERMOD_VERSION .. " : MiniMap Button |cFF00FF00Now |cFFFF0000Hidden ", .2, .0);
	  return;
	end
	if (string.lower(msg) == "menu") then
		PlaySound("igMainMenuOpen");
		ShowUIPanel(ShaderModOptionsFrame);
	  return;
	end

	if (string.lower(msg) == "options") then
		PlaySound("igMainMenuOpen");
		ShowUIPanel(ShaderModOptionsFrame);
	  return;
	end

	if (string.lower(msg) == "version") then
		DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFSky-|cFF0000FFDexter. |cFF00FF00ShaderMod |cFFFFFFFFCurrent Version: " .. SHADERMOD_VERSION, .2, .0);
	  return;
	end
	
	if (string.lower(msg) == "resetconfig") then
		SMSetDefaultOptions();
		DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFFSky-|cFF0000FFDexter. |cFF00FF00ShaderMod |cFFFFFFFFConfiguration Reset.", .2, .0);
	  return;
	end
	
	SMDisplayHelp();
end


function SMOnEvent(event, arg1)
	if (event == "VARIABLES_LOADED") then 
		SMInitialize(); 
	if (SMData[SMPlayerRealm][SMPlayerName].JustifyH_Left == true) then
		SMMessageFrame:SetJustifyH("Left");
	end	
	if (SMData[SMPlayerRealm][SMPlayerName].JustifyH_Center == true) then
		SMMessageFrame:SetJustifyH("Center");
	end
	if (SMData[SMPlayerRealm][SMPlayerName].JustifyH_Right == true) then
		SMMessageFrame:SetJustifyH("Right");
	end
	if (SMData[SMPlayerRealm][SMPlayerName].SMiniMapButton_Visible == false) then
		SMMiniMapButton:Hide();
	end
	if (SMData[SMPlayerRealm][SMPlayerName].SMiniMapButton_Locked == true) then
		SMMiniMapButton.Locked = true;
	end
		if(myAddOnsFrame) then
			myAddOnsList.CritCombo = { name = "ShaderMod",
						description = "Shadermod ",
						version = SHADERMOD_VERSION,
						category = MYADDONS_CATEGORY_COMBAT,
						optionsframe = "ShaderModOptionsFrame"
					};
		end
	end
	
	if (event == "CHAT_MSG_SPELL_SELF_DAMAGE") then
		CurrentSpell = 0;
		for spellname, creaturename, damage in string.gfind(arg1, SPELL_HIT)do
		CurrentSpell = tostring(spellname);
if ((CurrentSpell == MOONFIRE) or 
(CurrentSpell == STARFIRE) or 
(CurrentSpell == WRATH) or 
(CurrentSpell == SWIPE) or 
(CurrentSpell == MAUL) or 
(CurrentSpell == CLAW) or
(CurrentSpell == MAIM) or
(CurrentSpell == LACERATE) or
(CurrentSpell == MANGLE) or 
(CurrentSpell == SHRED) or 
(CurrentSpell == RAVAGE) or 
(CurrentSpell == POUNCE) or 
(CurrentSpell == FEROCIOUS_BITE) or 
(CurrentSpell == RAPTOR_STRIKE) or
(CurrentSpell == STEADY_SHOT) or
(CurrentSpell == SILENCING_SHOT) or 
(CurrentSpell == AUTO_SHOT) or 
(CurrentSpell == ARCANE_SHOT) or 
(CurrentSpell == MULTI_SHOT) or 
(CurrentSpell == AIMED_SHOT) or 
(CurrentSpell == ARCANE_MISSILES) or 
(CurrentSpell == FIRE_BLAST) or 
(CurrentSpell == FIREBALL) or
(CurrentSpell == PYROBLAST) or  
(CurrentSpell == INCINERATE) or 
(CurrentSpell == SCORCH) or 
(CurrentSpell == FROSTBOLT) or 
(CurrentSpell == ICE_LANCE) or 
(CurrentSpell == SMITE) or 
(CurrentSpell == MIND_BLAST) or 
(CurrentSpell == HOLY_FIRE) or
(CurrentSpell == SHADOWWORD_DEATH) or 
(CurrentSpell == BACKSTAB) or 
(CurrentSpell == SINISTER_STRIKE) or 
(CurrentSpell == EVISCERATE) or 
(CurrentSpell == DEADLY_THROW) or
(CurrentSpell == ENVENOM) or
(CurrentSpell == SHIV) or
(CurrentSpell == MUTILATE) or
(CurrentSpell == AMBUSH) or 
(CurrentSpell == BLADE_FLURRY) or 
(CurrentSpell == RIPOSTE) or 
(CurrentSpell == EARTH_SHOCK) or 
(CurrentSpell == FLAME_SHOCK) or
(CurrentSpell == LIGHTNING_BOLT) or 
(CurrentSpell == CHAIN_LIGHTNING) or 
(CurrentSpell == FROST_SHOCK) or  
(CurrentSpell == SEARING_PAIN) or 
(CurrentSpell == IMMOLATE) or 
(CurrentSpell == SOUL_FIRE) or 
(CurrentSpell == CONFLAGRATE) or 
(CurrentSpell == SHADOWBURN) or 
(CurrentSpell == SHADOW_BOLT) or 
(CurrentSpell == HEROIC_STRIKE) or 
(CurrentSpell == SLAM) or 
(CurrentSpell == RETALIATION) or 
(CurrentSpell == EXECUTE) or 
(CurrentSpell == OVERPOWER) or 
(CurrentSpell == CLEAVE) or 
(CurrentSpell == VICTORY_RUSH) or
(CurrentSpell == RAMPAGE) or
(CurrentSpell == DEVASTATE) or
(CurrentSpell == WHIRLWIND) or 
(CurrentSpell == MORTAL_STRIKE) or 
(CurrentSpell == SWEEPING_STRIKES) or 
(CurrentSpell == CRUSADER_STRIKE) or
(CurrentSpell == AVENGERS_STRIKE) or
(CurrentSpell == SHIELD_SLAM) or 
(CurrentSpell == EXORCISM) or
(CurrentSpell == JUDGEMENT_OF_COMMAND) or
(CurrentSpell == SEAL_OF_COMMAND) or
(CurrentSpell == JUDGEMENT_OF_RIGHTEOUSNESS) or
(CurrentSpell == ANOTHER_SPELL1) or
(CurrentSpell == ANOTHER_SPELL2) or
(CurrentSpell == ANOTHER_SPELL3) or
(CurrentSpell == ANOTHER_SPELL4) or
(CurrentSpell == ANOTHER_SPELL5) or
(CurrentSpell == HOLY_SHOCK)) then
					if ((SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Finish_Him == true) and (GetComboPoints("Player") == 5)) then
						PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\finishhim.wav");
					end
					if (CritCombo ~= 0) then
						SMCompare_Combos();
					end
					if ((SMData[SMPlayerRealm][SMPlayerName].Running_Hit_Display == true) and (SMData[SMPlayerRealm][SMPlayerName].Running_Combat_Log_Display == true)) then
					SMMessageFrame:AddMessage(" [" .. damage .. "] Damage" , DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
					end
			end
		end
		for spellname, creaturename, damage in string.gfind(arg1, SPELL_HIT2)do
		CurrentSpell = tostring(spellname);
if ((CurrentSpell == MOONFIRE) or 
(CurrentSpell == STARFIRE) or 
(CurrentSpell == WRATH) or 
(CurrentSpell == SWIPE) or 
(CurrentSpell == MAUL) or 
(CurrentSpell == CLAW) or
(CurrentSpell == MAIM) or
(CurrentSpell == LACERATE) or
(CurrentSpell == MANGLE) or 
(CurrentSpell == SHRED) or 
(CurrentSpell == RAVAGE) or 
(CurrentSpell == POUNCE) or 
(CurrentSpell == FEROCIOUS_BITE) or 
(CurrentSpell == RAPTOR_STRIKE) or
(CurrentSpell == STEADY_SHOT) or
(CurrentSpell == SILENCING_SHOT) or 
(CurrentSpell == AUTO_SHOT) or 
(CurrentSpell == ARCANE_SHOT) or 
(CurrentSpell == MULTI_SHOT) or 
(CurrentSpell == AIMED_SHOT) or 
(CurrentSpell == ARCANE_MISSILES) or 
(CurrentSpell == FIRE_BLAST) or 
(CurrentSpell == FIREBALL) or
(CurrentSpell == PYROBLAST) or  
(CurrentSpell == INCINERATE) or 
(CurrentSpell == SCORCH) or 
(CurrentSpell == FROSTBOLT) or 
(CurrentSpell == ICE_LANCE) or 
(CurrentSpell == SMITE) or 
(CurrentSpell == MIND_BLAST) or 
(CurrentSpell == HOLY_FIRE) or
(CurrentSpell == SHADOWWORD_DEATH) or 
(CurrentSpell == BACKSTAB) or 
(CurrentSpell == SINISTER_STRIKE) or 
(CurrentSpell == EVISCERATE) or 
(CurrentSpell == DEADLY_THROW) or
(CurrentSpell == ENVENOM) or
(CurrentSpell == SHIV) or
(CurrentSpell == MUTILATE) or
(CurrentSpell == AMBUSH) or 
(CurrentSpell == BLADE_FLURRY) or 
(CurrentSpell == RIPOSTE) or 
(CurrentSpell == EARTH_SHOCK) or 
(CurrentSpell == FLAME_SHOCK) or
(CurrentSpell == LIGHTNING_BOLT) or 
(CurrentSpell == CHAIN_LIGHTNING) or 
(CurrentSpell == FROST_SHOCK) or  
(CurrentSpell == SEARING_PAIN) or 
(CurrentSpell == IMMOLATE) or 
(CurrentSpell == SOUL_FIRE) or 
(CurrentSpell == CONFLAGRATE) or 
(CurrentSpell == SHADOWBURN) or 
(CurrentSpell == SHADOW_BOLT) or 
(CurrentSpell == HEROIC_STRIKE) or 
(CurrentSpell == SLAM) or 
(CurrentSpell == RETALIATION) or 
(CurrentSpell == EXECUTE) or 
(CurrentSpell == OVERPOWER) or 
(CurrentSpell == CLEAVE) or 
(CurrentSpell == VICTORY_RUSH) or
(CurrentSpell == RAMPAGE) or
(CurrentSpell == DEVASTATE) or
(CurrentSpell == WHIRLWIND) or 
(CurrentSpell == MORTAL_STRIKE) or 
(CurrentSpell == SWEEPING_STRIKES) or 
(CurrentSpell == CRUSADER_STRIKE) or
(CurrentSpell == AVENGERS_STRIKE) or
(CurrentSpell == SHIELD_SLAM) or 
(CurrentSpell == EXORCISM) or
(CurrentSpell == JUDGEMENT_OF_COMMAND) or
(CurrentSpell == SEAL_OF_COMMAND) or
(CurrentSpell == JUDGEMENT_OF_RIGHTEOUSNESS) or
(CurrentSpell == ANOTHER_SPELL1) or
(CurrentSpell == ANOTHER_SPELL2) or
(CurrentSpell == ANOTHER_SPELL3) or
(CurrentSpell == ANOTHER_SPELL4) or
(CurrentSpell == ANOTHER_SPELL5) or
(CurrentSpell == HOLY_SHOCK)) then
					if ((SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Finish_Him == true) and (GetComboPoints("Player") == 5)) then
						PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\finishhim.wav");
					end
					if (CritCombo ~= 0) then
						SMCompare_Combos();
					end
					if ((SMData[SMPlayerRealm][SMPlayerName].Running_Hit_Display == true) and (SMData[SMPlayerRealm][SMPlayerName].Running_Combat_Log_Display == true)) then
					SMMessageFrame:AddMessage(" [" .. damage .. "] Damage" , DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
					end
			end
		end
		for spellname, creaturename, damage in string.gfind(arg1, SPELL_CRIT)do
		CurrentSpell = tostring(spellname);
if ((CurrentSpell == MOONFIRE) or 
(CurrentSpell == STARFIRE) or 
(CurrentSpell == WRATH) or 
(CurrentSpell == SWIPE) or 
(CurrentSpell == MAUL) or 
(CurrentSpell == CLAW) or
(CurrentSpell == MAIM) or
(CurrentSpell == LACERATE) or
(CurrentSpell == MANGLE) or 
(CurrentSpell == SHRED) or 
(CurrentSpell == RAVAGE) or 
(CurrentSpell == POUNCE) or 
(CurrentSpell == FEROCIOUS_BITE) or 
(CurrentSpell == RAPTOR_STRIKE) or
(CurrentSpell == STEADY_SHOT) or
(CurrentSpell == SILENCING_SHOT) or 
(CurrentSpell == AUTO_SHOT) or 
(CurrentSpell == ARCANE_SHOT) or 
(CurrentSpell == MULTI_SHOT) or 
(CurrentSpell == AIMED_SHOT) or 
(CurrentSpell == ARCANE_MISSILES) or 
(CurrentSpell == FIRE_BLAST) or 
(CurrentSpell == FIREBALL) or
(CurrentSpell == PYROBLAST) or  
(CurrentSpell == INCINERATE) or 
(CurrentSpell == SCORCH) or 
(CurrentSpell == FROSTBOLT) or 
(CurrentSpell == ICE_LANCE) or 
(CurrentSpell == SMITE) or 
(CurrentSpell == MIND_BLAST) or 
(CurrentSpell == HOLY_FIRE) or
(CurrentSpell == SHADOWWORD_DEATH) or 
(CurrentSpell == BACKSTAB) or 
(CurrentSpell == SINISTER_STRIKE) or 
(CurrentSpell == EVISCERATE) or 
(CurrentSpell == DEADLY_THROW) or
(CurrentSpell == ENVENOM) or
(CurrentSpell == SHIV) or
(CurrentSpell == MUTILATE) or
(CurrentSpell == AMBUSH) or 
(CurrentSpell == BLADE_FLURRY) or 
(CurrentSpell == RIPOSTE) or 
(CurrentSpell == EARTH_SHOCK) or 
(CurrentSpell == FLAME_SHOCK) or
(CurrentSpell == LIGHTNING_BOLT) or 
(CurrentSpell == CHAIN_LIGHTNING) or 
(CurrentSpell == FROST_SHOCK) or  
(CurrentSpell == SEARING_PAIN) or 
(CurrentSpell == IMMOLATE) or 
(CurrentSpell == SOUL_FIRE) or 
(CurrentSpell == CONFLAGRATE) or 
(CurrentSpell == SHADOWBURN) or 
(CurrentSpell == SHADOW_BOLT) or 
(CurrentSpell == HEROIC_STRIKE) or 
(CurrentSpell == SLAM) or 
(CurrentSpell == RETALIATION) or 
(CurrentSpell == EXECUTE) or 
(CurrentSpell == OVERPOWER) or 
(CurrentSpell == CLEAVE) or 
(CurrentSpell == VICTORY_RUSH) or
(CurrentSpell == RAMPAGE) or
(CurrentSpell == DEVASTATE) or
(CurrentSpell == WHIRLWIND) or 
(CurrentSpell == MORTAL_STRIKE) or 
(CurrentSpell == SWEEPING_STRIKES) or 
(CurrentSpell == CRUSADER_STRIKE) or
(CurrentSpell == AVENGERS_STRIKE) or
(CurrentSpell == SHIELD_SLAM) or 
(CurrentSpell == EXORCISM) or
(CurrentSpell == JUDGEMENT_OF_COMMAND) or
(CurrentSpell == SEAL_OF_COMMAND) or
(CurrentSpell == JUDGEMENT_OF_RIGHTEOUSNESS) or
(CurrentSpell == ANOTHER_SPELL1) or
(CurrentSpell == ANOTHER_SPELL2) or
(CurrentSpell == ANOTHER_SPELL3) or
(CurrentSpell == ANOTHER_SPELL4) or
(CurrentSpell == ANOTHER_SPELL5) or
(CurrentSpell == HOLY_SHOCK)) then

				if ((SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Finish_Him == true) and (GetComboPoints("Player") == 5)) then
					PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\finishhim.wav");
				end
				CritDmg = tonumber(damage);
				CritCombo = CritCombo + 1;
				CritComboDmg = CritComboDmg + damage;
				if (CritCombo >= 1) then
							if (CritCombo > 0 and CritCombo < 2) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Yeah == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\yeah.wav");
								end
								CritMsg = "Yeah!";
--								SMMessageFrame:AddMessage("Yeah! x" .. CritCombo .. " [" .. CritComboDmg .. "] total damage" , DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (CritCombo > 1 and CritCombo < 3) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Oh_Yeah == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\ohyeah.wav");
								end
								CritMsg = "Oh Yeah!";
--								SMMessageFrame:AddMessage("Oh Yeah! x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (CritCombo > 2 and CritCombo < 4) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Unstoppable == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\unstoppable.wav");
								end
								CritMsg = "Unstoppable!";
--								SMMessageFrame:AddMessage("Unstoppable! x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (CritCombo > 3 and CritCombo < 5) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Killing_Spree == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\killer.wav");
								end
								CritMsg = "Killing Spree!";
--								SMMessageFrame:AddMessage("Killing Spree! x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (CritCombo > 4 and CritCombo < 6) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Dominating == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\dominating.wav");
								end
								CritMsg = "Dominating!";
--								SMMessageFrame:AddMessage("Dominating! x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (CritCombo > 5 and CritCombo < 7) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Ultra_Kill == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\ultrakill.wav");
								end
								CritMsg = "Ultra Kill!";
--								SMMessageFrame:AddMessage("Ultra Kill! x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (CritCombo > 6 and CritCombo < 8) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Wicked_Sick == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\wickedsick.wav");
								end
								CritMsg = "Wicked Sick!";
--								SMMessageFrame:AddMessage("Wicked Sick! x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (CritCombo > 7 and CritCombo < 10) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_God_Like == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\godlike.wav");
								end
								CritMsg = "God Like!";
--								SMMessageFrame:AddMessage("God Like! x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (CritCombo > 9 and CritCombo < 15) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Holy_Shit == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\holyshit.wav");
								end
								CritMsg = "Holy Shit!";
--								SMMessageFrame:AddMessage("Holy Shit! x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (CritCombo > 14 and CritCombo < 20) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Monster_Kill == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\monsterkill.wav");
								end
								CritMsg = "Mm-mmm-Monster Kill!";
--								SMMessageFrame:AddMessage("Mm-mmm-Monster Kill! x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (CritCombo > 19 and CritCombo < 22) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Ludicrous_Kill == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\ludicrouskill.wav");
								end
								CritMsg = "Lu-lu-lu-lu-ludicrous kill!";
--								SMMessageFrame:AddMessage("Lu-lu-lu-lu-ludicrous Kill! x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (CritCombo > 21) then
								if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Ownage == true) then
									PlaySoundFile("Interface\\AddOns\\ShaderMod\\Sounds\\ownage.wav");
								end
								CritMsg = "Ownage!";
--								SMMessageFrame:AddMessage("Ownage! x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if ((SMData[SMPlayerRealm][SMPlayerName].Running_Crit_Display == true) and (SMData[SMPlayerRealm][SMPlayerName].Running_Combat_Log_Display == true)) then
							SMMessageFrame:AddMessage(CritMsg .. " x" .. CritCombo .. " [" .. CritComboDmg .. "] total damage (+" .. damage .. ")" , DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
							if (SMData[SMPlayerRealm][SMPlayerName].Running_Old_School_Display == true) then
							SMMessageFrame:AddMessage(CritMsg .. " x" .. CritCombo, DISPLAY_RED, DISPLAY_GREEN, DISPLAY_BLUE, 1, 3);
							end
				end
			end
		end	
	end
	
	if (event == "PLAYER_REGEN_ENABLED") then
		if (SMData[SMPlayerRealm][SMPlayerName].Reset_Combo == true and CritCombo ~= 0) then
			SMCompare_Combos();
		end
	end

end

function SMCompare_Combos()
	extra_crits_toggle = 0;
	if (CritCombo >= SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritCombo and CritComboDmg >= SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritComboDmg) then
		SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritCombo = CritCombo;
		SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritComboDmg = CritComboDmg;
		SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritCombo = CritCombo;
		SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritComboDmg = CritComboDmg;
	else
		if (CritCombo >= SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritCombo) then
			if (CritCombo == SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritCombo) then
				if (CritComboDmg > SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritComboDmg) then
					SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritCombo = CritCombo;
					SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritComboDmg = CritComboDmg;
				end
			end
			if (CritCombo > SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritCombo) then
				SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritCombo = CritCombo;
				SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritComboDmg = CritComboDmg;
			end
		end
		
		if (CritComboDmg >= SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritComboDmg) then
			if (CritComboDmg == SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritComboDmg) then
				if (CritCombo > SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritCombo) then
					SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritCombo = CritCombo;
					SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritComboDmg = CritComboDmg;
				end
			end
			if (CritComboDmg > SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritComboDmg) then
				SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritCombo = CritCombo;
				SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritComboDmg = CritComboDmg;
			end
		end
	end
	
if (SMData[SMPlayerRealm][SMPlayerName].Party_Display == true) then
	if ((CritCombo > 21)) then
		SendChatMessage("[ShaderMod] Ownage!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "PARTY");
	else
		if ((CritCombo > 19 and CritCombo < 22)) then
			SendChatMessage("[ShaderMod] Lu-lu-lu-lu-ludicrous Kill!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "PARTY");
		else
			if ((CritCombo > 14 and CritCombo < 19)) then
				SendChatMessage("[ShaderMod] Mm-mmm-Monster Kill!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "PARTY");
		     	else
			   	 if ((CritCombo > 9 and CritCombo < 15)) then
					    SendChatMessage("[ShaderMod] Holy Shit!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "PARTY");
			 	else
					if ((CritCombo > 7 and CritCombo < 10)) then
						SendChatMessage("[ShaderMod] God Like!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "PARTY");
					else
						if ((CritCombo > 6 and CritCombo < 8)) then
							SendChatMessage("[ShaderMod] Wicked Sick!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "PARTY");
						else
							if ((CritCombo > 5 and CritCombo < 7)) then
								SendChatMessage("[ShaderMod] Ultra Kill!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "PARTY");
							end

						end
					end
				end
			end
		end
	end
 end

if (SMData[SMPlayerRealm][SMPlayerName].Raid_Display == true) then
	if ((CritCombo > 21)) then
		SendChatMessage("[ShaderMod] Ownage!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "RAID");
	else
		if ((CritCombo > 19 and CritCombo < 22)) then
			SendChatMessage("[ShaderMod] Lu-lu-lu-lu-ludicrous Kill!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "RAID");
		else
			if ((CritCombo > 14 and CritCombo < 19)) then
				SendChatMessage("[ShaderMod] Mm-mmm-Monster Kill!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "RAID");
		     	else
			   	 if ((CritCombo > 9 and CritCombo < 15)) then
					    SendChatMessage("[ShaderMod] Holy Shit!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "RAID");
			 	else
					if ((CritCombo > 7 and CritCombo < 10)) then
						SendChatMessage("[ShaderMod] God Like!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "RAID");
					else
						if ((CritCombo > 6 and CritCombo < 8)) then
							SendChatMessage("[ShaderMod] Wicked Sick!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "RAID");
						else
							if ((CritCombo > 5 and CritCombo < 7)) then
								SendChatMessage("[ShaderMod] Ultra Kill!  *" .. CritCombo .. "* crits for *" .. CritComboDmg .. "* damage! ", "RAID");
							end

						end
					end
				end
			end
		end
	end
 end
	
	CritCombo = 0;
	CritComboDmg = 0;
end

function SMInitializeSMData()
	if (SMData == nil) then
		SMData = {};
	end
	
	if (SMData[SMPlayerRealm] == nil) then
		SMData[SMPlayerRealm] = {};
	end

	if (SMPlayerName ~= nil and SMPlayerName ~= UNKNOWNOBJECT and SMPlayerName ~= UKNOWNBEING) then
		if (SMData[SMPlayerRealm][SMPlayerName] == nil) then
			SMData[SMPlayerRealm][SMPlayerName] = {};
			SMSetCurrentPlayerToZeros();
			SMSetDefaultOptions();
		end
	end
end

function SMSetCurrentPlayerToZeros()
	SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritCombo = 0;
	SMData[SMPlayerRealm][SMPlayerName].RecordHitsCritComboDmg = 0;
	SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritCombo = 0;
	SMData[SMPlayerRealm][SMPlayerName].RecordDmgCritComboDmg = 0;
end

function SMResetAll()
	SMData = {};
	SMInitializeSMData();
	SMOptionsFrame_OnShow();
		
	DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[ShaderMod] " .. SHADERMOD_VERSION .. " All records and options reset.", .2, .0);
end

function SMDisplayHelp()
	DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[ShaderMod] " .. SHADERMOD_VERSION .. " |cFF00FF00: Modded by |cFF00FFFFSky-|cFF0000FFDexter.", .2, .0);
	DEFAULT_CHAT_FRAME:AddMessage("[Commands] (/ShaderMod, /ShaderM, /sm)",.65,.65,.6);
	DEFAULT_CHAT_FRAME:AddMessage("   Menu - Shows the options menu.");
	DEFAULT_CHAT_FRAME:AddMessage("   Records - Shows your records.");
	DEFAULT_CHAT_FRAME:AddMessage("   Version - Displays current version.");
	DEFAULT_CHAT_FRAME:AddMessage("   Lock/Unlock - Lock or unlock message frame.");
	DEFAULT_CHAT_FRAME:AddMessage("   Hide/Show - Hide or show message frame.");
	DEFAULT_CHAT_FRAME:AddMessage("   MiniMap Lock/Unlock - Lock or Unlock the minimap button.");
	DEFAULT_CHAT_FRAME:AddMessage("   MiniMap Hide/Show - Hide or Show the minimap button.");
end

function SMOptionsFrame_OnShow()	
	if (SMData[SMPlayerRealm][SMPlayerName].Running_Crit_Display) then
		SMCheckBoxRunning_Crit_Display:SetChecked(1);
	else
		SMCheckBoxRunning_Crit_Display:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Running_Combat_Log_Display) then
		SMCheckBoxRunning_Combat_Log_Display:SetChecked(1);
	else
		SMCheckBoxRunning_Combat_Log_Display:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Running_Old_School_Display) then
		SMCheckBoxRunning_Old_School_Display:SetChecked(1);
	else
		SMCheckBoxRunning_Old_School_Display:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Running_Hit_Display) then
		SMCheckBoxRunning_Hit_Display:SetChecked(1);
	else
		SMCheckBoxRunning_Hit_Display:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Reset_Combo) then
		SMCheckBoxRunning_Reset_Combo:SetChecked(1);
	else
		SMCheckBoxRunning_Reset_Combo:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Party_Display) then
		SMCheckBoxParty_Display:SetChecked(1);
	else
		SMCheckBoxParty_Display:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Raid_Display) then
		SMCheckBoxRaid_Display:SetChecked(1);
	else
		SMCheckBoxRaid_Display:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Finish_Him) then
		SMCheckBoxEnable_Sound_Finish_Him:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Finish_Him:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Yeah) then
		SMCheckBoxEnable_Sound_Yeah:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Yeah:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Oh_Yeah) then
		SMCheckBoxEnable_Sound_Oh_Yeah:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Oh_Yeah:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Unstoppable) then
		SMCheckBoxEnable_Sound_Unstoppable:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Unstoppable:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Killing_Spree) then
		SMCheckBoxEnable_Sound_Killing_Spree:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Killing_Spree:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Dominating) then
		SMCheckBoxEnable_Sound_Dominating:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Dominating:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Ultra_Kill) then
		SMCheckBoxEnable_Sound_Ultra_Kill:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Ultra_Kill:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Wicked_Sick) then
		SMCheckBoxEnable_Sound_Wicked_Sick:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Wicked_Sick:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_God_Like) then
		SMCheckBoxEnable_Sound_God_Like:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_God_Like:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Holy_Shit) then
		SMCheckBoxEnable_Sound_Holy_Shit:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Holy_Shit:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Monster_Kill) then
		SMCheckBoxEnable_Sound_Monster_Kill:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Monster_Kill:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Ludicrous_Kill) then
		SMCheckBoxEnable_Sound_Ludicrous_Kill:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Ludicrous_Kill:SetChecked(0);
	end

	if (SMData[SMPlayerRealm][SMPlayerName].Enable_Sound_Ownage) then
		SMCheckBoxEnable_Sound_Ownage:SetChecked(1);
	else
		SMCheckBoxEnable_Sound_Ownage:SetChecked(0);
	end
end

function SMCheckBoxClick(var_to_toggle)
	if ( this:GetChecked() ) then
		var_to_toggle = true;
	else
		var_to_toggle = false;
	end
end