-- Modified code from soulfilcher's Model Tweak API
-- require 'ModelTweaker_Core'

if not TweakWeaponModelAttachmentData then TweakWeaponModelAttachmentData = {} end

function TweakWeaponModelAttachments()
	local model;
	for k,v in pairs(TweakWeaponModelAttachmentData) do 
		for t,y in pairs(v) do 
			model = ScriptManager.instance:getModelScript(k);		
			if model ~= nil then
				local name = model:getName();
				model:Load(name, "{" ..t.. "\n{".."\n"..y.."\n}\n");
				print(k..": "..t..", "..y);
			end
		end
	end
end

function TweakWeaponModelAttachment(modelName, modelProperty, propertyValue)
	if not TweakWeaponModelAttachmentData[modelName] then
		TweakWeaponModelAttachmentData[modelName] = {};
	end
	TweakWeaponModelAttachmentData[modelName][modelProperty] = propertyValue;
end

Events.OnGameBoot.Add(TweakWeaponModelAttachments)

-- Fixes vanilla attachment offsets
TweakWeaponModelAttachment("Base.Shotgun", "attachment muzzle", "offset = 0.0000 0.4680 0.0300, rotate = 0.0000 0.0000 90.0000,");
TweakWeaponModelAttachment("Base.ShotgunSawnOff", "attachment muzzle", "offset = 0.0000 0.3200 0.0300, rotate = 0.0000 0.0000 90.0000,");
TweakWeaponModelAttachment("Base.Revolver_Long", "attachment muzzle", "offset = 0.0000 0.1710 -0.0280, rotate = -90.0000 0.0000 0.0000,");

-- TweakWeaponModelAttachment("Base.AssaultRifle02", "attachment muzzle", "offset = 0.0000 0.4750 0.0350, rotate = -90.0000 0.0000 180.0000,");
-- TweakWeaponModelAttachment("Base.AssaultRifle02", "attachment scope", "offset = 0.0000 0.0600 0.0600, rotate = 0.0000 0.0000 0.0000,");
-- TweakWeaponModelAttachment("Base.AssaultRifle02", "attachment scope2", "offset = 0.0000 0.0700 0.0400, rotate = 0.0000 0.0000 0.0000,");
-- TweakWeaponModelAttachment("Base.AssaultRifle02", "attachment reddot", "offset = 0.0000 0.0500 0.0500, rotate = 180.0000 0.0000 -180.0000,");
-- TweakWeaponModelAttachment("Base.AssaultRifle02", "attachment laser", "offset = 0.0000 0.2800 0.0100, rotate = 180.0000 0.0000 180.0000,");
-- TweakWeaponModelAttachment("Base.AssaultRifle02", "attachment recoilpad", "offset = 0.0000 -0.1200 -0.0250, rotate = 0.0000 0.0000 0.0000,");

TweakWeaponModelAttachment("Base.M14", "attachment muzzle", "offset = 0.0000 0.4750 0.0350, rotate = -90.0000 0.0000 180.0000,");
TweakWeaponModelAttachment("Base.M14", "attachment scope", "offset = 0.0000 0.0350 0.0540, rotate = 0.0000 0.0000 0.0000,");
TweakWeaponModelAttachment("Base.M14", "attachment scope2", "offset = 0.0000 0.0210 0.0610, rotate = 0.0000 0.0000 0.0000,");
TweakWeaponModelAttachment("Base.M14", "attachment reddot", "offset = 0.0000 0.0500 0.0500, rotate = 180.0000 0.0000 -180.0000,");
TweakWeaponModelAttachment("Base.M14", "attachment laser", "offset = 0.0000 0.2800 0.0100, rotate = 180.0000 0.0000 180.0000,");
TweakWeaponModelAttachment("Base.M14", "attachment recoilpad", "offset = 0.0000 -0.1200 -0.0250, rotate = 0.0000 0.0000 0.0000,");

TweakWeaponModelAttachment("Base.AssaultRifle", "attachment muzzle", "offset = 0.0000 0.4020 0.0270, rotate = -90.0000 0.0000 180.0000,");
TweakWeaponModelAttachment("Base.AssaultRifle", "attachment scope", "offset = 0.0000 0.0100 0.0800, rotate = 0.0000 0.0000 0.0000,");
TweakWeaponModelAttachment("Base.AssaultRifle", "attachment scope2", "offset = 0.0000 0.0400 0.0700, rotate = 0.0000 0.0000 0.0000,");
TweakWeaponModelAttachment("Base.AssaultRifle", "attachment reddot", "offset = 0.0010 0.0150 0.0670, rotate = 180.0000 0.0000 -180.0000,");
TweakWeaponModelAttachment("Base.AssaultRifle", "attachment laser", "offset = 0.0000 0.2340 0.0020, rotate = 180.0000 0.0000 180.0000,");
TweakWeaponModelAttachment("Base.AssaultRifle", "attachment recoilpad", "offset = 0.0000 -0.1450 0.0050, rotate = 0.0000 0.0000 0.0000,");