<commit_before>/**
 * Disguiser SWEP - Lets you disguise as any prop on a map.
 *
 * File:
 *   init.lua
 *
 * Purpose:
 *   Initializes server-side stuff including weapon information, actual weapon
 *   hooks and whatever stuff is also needed to make the server work on servers.
 *
 * Copyright (C) 2013 <NAME> (Icedream)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

 // Weapon info for server
SWEP.Weight = 5
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = false
SWEP.ShouldDropOnDie = false

// DEBUG DEBUG DEBUG
print("[Disguiser] Loading serverside...")

// Downloads for the client
// TODO: Dynamic file addition here
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("cl_3rdperson.lua")
AddCSLuaFile("cl_obb.lua")
AddCSLuaFile("cl_fxfake.lua")
AddCSLuaFile("sh_init.lua")

// Shared stuff
include("sh_init.lua")

// Local stuff
SWEP.UndisguiseAs = nil
SWEP.UndisguiseAsMass = nil
SWEP.UndisguiseAsSkin = nil
SWEP.UndisguiseAsSolid = nil
SWEP.UndisguiseAsFullRotation = nil
SWEP.DisguisedAs = nil

// Banned prop models
SWEP.PropConfiguration = {
	["models/props/cs_assault/dollar.mdl"] = {
		Banned = true
	},
	["models/props/cs_assault/money.mdl"] = {
		Banned = true
	},
	["models/props/cs_office/snowman_arm.mdl"] = {
		Banned = true
	},
	["models/props/cs_office/computer_mouse.mdl"] = {
		Banned = true
	},
	["models/props/cs_office/projector_remote.mdl"] = {
		Banned = true
	},
	["models/props_junk/bicycle01a.mdl"] = {
		// The bicycle in cs_italy has a too big bounding box, you
		// can't even get through doors without this correction
		OBBMinsCorrection = Vector(28, -28, 0),
		OBBMaxsCorrection = Vector(-28, 28, 0)
	}
	// TODO: There is another item on cs_office which needs to be corrected. Forgot which one though.
}

// Door exploits
local ExploitableDoors = {
	"func_door",
	"prop_door_rotating",
	"func_door_rotating"
}

// The actual disguise action
function SWEP:Disguise(entity)
	
	// Make sure the model file is not banned
	if self:HasPropConfig(entity:GetModel()) && self:GetPropConfig(entity:GetModel()).Banned then
		umsg.Start("cantDisguiseAsBannedProp")
		umsg.End()
		return
	end
	
	// Make sure we are valid
	if (!IsValid(self)) then return false end
	
	// Make sure the player is alive and valid
	if (!IsValid(self.Owner) || !self.Owner:Alive()) then return false end
	
	local owner = self.Owner
	
	// Make sure we aren't already that model
	if (owner:GetModel() == entity:GetModel() && owner:GetSkin() == entity:GetSkin()) then return true end
	
	local physobj = entity:GetPhysicsObject()
	local ophysobj = owner:GetPhysicsObject()
	
	// Back up model
	if (!self.UndisguiseAs) then
		self.UndisguiseAs = owner:GetModel()
		self.UndisguiseAsSkin = owner:GetSkin()
		self.UndisguiseAsMass = ophysobj:GetMass()
		self.UndisguiseAsBloodColor = owner:GetBloodColor()
		self.UndisguiseAsSolid = owner:GetSolid()
		self.UndisguiseAsFullRotation = owner:GetAllowFullRotation()
	end
	
	// Disguise as given model
	self:EnableThirdPerson(owner)
	owner:DrawViewModel(false)
	owner:DrawWorldModel(false)
	owner:SetModel(entity:GetModel())
	owner:SetSolid(SOLID_BSP)
	owner:SetBloodColor(BLOOD_COLOR_RED)
	owner:SetSkin(entity:GetSkin()) // coloring
	owner:SetPos(owner:GetPos() - Vector(0, 0, entity:OBBMins().z - 2)) // anti-stuck
	
	// Apply new physics, too
	ophysobj:SetMass(physobj:GetMass())
	self:UpdateHealth(math.Clamp(physobj:GetVolume() / 300, 1, 200))
	
	// Apply new hull
	local obbmaxs = entity:OBBMaxs()
	local obbmins = entity:OBBMins()
	/*
	local obbmargin = Vector(2, 2, 0)
	obbmaxs = obbmaxs + obbmargin
	obbmins = obbmins - obbmargin
	*/
	// Look for correction values
	local pcfg = self:GetPropConfig(entity:GetModel())
	if !!pcfg["OBBMaxsCorrection"] then
		obbmaxs = obbmaxs + pcfg["OBBMaxsCorrection"]
	end
	if !!pcfg["OBBMinsCorrection"] then
		obbmins = obbmins + pcfg["OBBMinsCorrection"]
	end
	owner:SetHull(obbmins, obbmaxs)
	owner:SetHullDuck(obbmins, obbmaxs) -- ducking shouldn't work for props
	
	// Notify all clients about the new hull so the player appears
	// correct for everyone
	umsg.Start("setBounding")
	umsg.Entity(owner)
	umsg.Vector(entity:OBBMins())
	umsg.Vector(entity:OBBMaxs())
	umsg.End()
	
	// Pop!
	owner:EmitSound("Disguiser.Disguise")
	
	// We're now disguised!
	self.DisguisedAs = entity:GetModel()
	owner.Disguised = true
	
	// DEBUG DEBUG DEBUG
	print(owner:Name() .. " switched to model " .. entity:GetModel())
	
	return true
end

// Undisguise
function SWEP:Undisguise()
	
	// Make sure we are valid
	if (!IsValid(self)) then return false end
	
	// Make sure the player is alive and valid
	if (!IsValid(self.Owner) || !self.Owner:Alive()) then return false end
	
	// Make sure we are disguised already
	if (self.DisguisedAs == nil) then return false end
	
	// Make sure we have an old model to revert to
	if (self.UndisguiseAs == nil) then return false end
	
	local owner = self.Owner
	local ophysobj = owner:GetPhysicsObject()
	
	// Revert to old model
	owner:SetModel(self.UndisguiseAs)
	owner:SetMoveType(MOVETYPE_WALK)
	owner:SetSkin(self.UndisguiseAsSkin)
	owner:SetSolid(self.UndisguiseAsSolid)
	owner:SetAllowFullRotation(self.UndisguiseAsFullRotation) // up/down rotation
	owner:SetBloodColor(self.UndisguiseAsBloodColor)
	
	// Revert to old physics
	ophysobj:SetMass(self.UndisguiseAsMass)
	self:UpdateHealth(100)
	
	// Hull reset
	owner:ResetHull()<commit_msg>GetSkin can have no value and also apply color.<commit_after>/**
 * Disguiser SWEP - Lets you disguise as any prop on a map.
 *
 * File:
 *   init.lua
 *
 * Purpose:
 *   Initializes server-side stuff including weapon information, actual weapon
 *   hooks and whatever stuff is also needed to make the server work on servers.
 *
 * Copyright (C) 2013 <NAME> (Icedream)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

 // Weapon info for server
SWEP.Weight = 5
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = false
SWEP.ShouldDropOnDie = false

// DEBUG DEBUG DEBUG
print("[Disguiser] Loading serverside...")

// Downloads for the client
// TODO: Dynamic file addition here
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("cl_3rdperson.lua")
AddCSLuaFile("cl_obb.lua")
AddCSLuaFile("cl_fxfake.lua")
AddCSLuaFile("sh_init.lua")

// Shared stuff
include("sh_init.lua")

// Local stuff
SWEP.UndisguiseAs = nil
SWEP.UndisguiseAsMass = nil
SWEP.UndisguiseAsSkin = nil
SWEP.UndisguiseAsSolid = nil
SWEP.UndisguiseAsFullRotation = nil
SWEP.DisguisedAs = nil

// Banned prop models
SWEP.PropConfiguration = {
	["models/props/cs_assault/dollar.mdl"] = {
		Banned = true
	},
	["models/props/cs_assault/money.mdl"] = {
		Banned = true
	},
	["models/props/cs_office/snowman_arm.mdl"] = {
		Banned = true
	},
	["models/props/cs_office/computer_mouse.mdl"] = {
		Banned = true
	},
	["models/props/cs_office/projector_remote.mdl"] = {
		Banned = true
	},
	["models/props_junk/bicycle01a.mdl"] = {
		// The bicycle in cs_italy has a too big bounding box, you
		// can't even get through doors without this correction
		OBBMinsCorrection = Vector(28, -28, 0),
		OBBMaxsCorrection = Vector(-28, 28, 0)
	}
	// TODO: There is another item on cs_office which needs to be corrected. Forgot which one though.
}

// Door exploits
local ExploitableDoors = {
	"func_door",
	"prop_door_rotating",
	"func_door_rotating"
}

// The actual disguise action
function SWEP:Disguise(entity)
	
	// Make sure the model file is not banned
	if self:HasPropConfig(entity:GetModel()) && self:GetPropConfig(entity:GetModel()).Banned then
		umsg.Start("cantDisguiseAsBannedProp")
		umsg.End()
		return
	end
	
	// Make sure we are valid
	if (!IsValid(self)) then return false end
	
	// Make sure the player is alive and valid
	if (!IsValid(self.Owner) || !self.Owner:Alive()) then return false end
	
	local owner = self.Owner
	
	// Make sure we aren't already that model
	if (owner:GetModel() == entity:GetModel() && owner:GetSkin() == entity:GetSkin()) then return true end
	
	local physobj = entity:GetPhysicsObject()
	local ophysobj = owner:GetPhysicsObject()
	
	// Back up model
	if (!self.UndisguiseAs) then
		self.UndisguiseAs = owner:GetModel()
		self.UndisguiseAsSkin = owner:GetSkin()
		self.UndisguiseAsMass = ophysobj:GetMass()
		self.UndisguiseAsColor = owner:GetColor()
		self.UndisguiseAsBloodColor = owner:GetBloodColor()
		self.UndisguiseAsSolid = owner:GetSolid()
		self.UndisguiseAsFullRotation = owner:GetAllowFullRotation()
	end
	
	// Disguise as given model
	self:EnableThirdPerson(owner)
	owner:DrawViewModel(false)
	owner:DrawWorldModel(false)
	owner:SetModel(entity:GetModel())
	owner:SetSolid(SOLID_BSP)
	owner:SetBloodColor(BLOOD_COLOR_RED)
	if entity:GetSkin() != nil then
		owner:SetSkin(entity:GetSkin()) // coloring
	end
	owner:SetColor(entity:GetColor())
	owner:SetPos(owner:GetPos() - Vector(0, 0, entity:OBBMins().z - 2)) // anti-stuck
	
	// Apply new physics, too
	ophysobj:SetMass(physobj:GetMass())
	self:UpdateHealth(math.Clamp(physobj:GetVolume() / 300, 1, 200))
	
	// Apply new hull
	local obbmaxs = entity:OBBMaxs()
	local obbmins = entity:OBBMins()
	/*
	local obbmargin = Vector(2, 2, 0)
	obbmaxs = obbmaxs + obbmargin
	obbmins = obbmins - obbmargin
	*/
	// Look for correction values
	local pcfg = self:GetPropConfig(entity:GetModel())
	if !!pcfg["OBBMaxsCorrection"] then
		obbmaxs = obbmaxs + pcfg["OBBMaxsCorrection"]
	end
	if !!pcfg["OBBMinsCorrection"] then
		obbmins = obbmins + pcfg["OBBMinsCorrection"]
	end
	owner:SetHull(obbmins, obbmaxs)
	owner:SetHullDuck(obbmins, obbmaxs) -- ducking shouldn't work for props
	
	// Notify all clients about the new hull so the player appears
	// correct for everyone
	umsg.Start("setBounding")
	umsg.Entity(owner)
	umsg.Vector(entity:OBBMins())
	umsg.Vector(entity:OBBMaxs())
	umsg.End()
	
	// Pop!
	owner:EmitSound("Disguiser.Disguise")
	
	// We're now disguised!
	self.DisguisedAs = entity:GetModel()
	owner.Disguised = true
	
	// DEBUG DEBUG DEBUG
	print(owner:Name() .. " switched to model " .. entity:GetModel())
	
	return true
end

// Undisguise
function SWEP:Undisguise()
	
	// Make sure we are valid
	if (!IsValid(self)) then return false end
	
	// Make sure the player is alive and valid
	if (!IsValid(self.Owner) || !self.Owner:Alive()) then return false end
	
	// Make sure we are disguised already
	if (self.DisguisedAs == nil) then return false end
	
	// Make sure we have an old model to revert to
	if (self.UndisguiseAs == nil) then return false end
	
	local owner = self.Owner
	local ophysobj = owner:GetPhysicsObject()
	
	// Revert to old model
	owner:SetModel(self.UndisguiseAs)
	owner:SetMoveType(MOVETYPE_WALK)
	if self.UndisguiseAsSkin != nil then
		owner:SetSkin(self.UndisguiseAsSkin)
	end
	owner:SetColor(self.UndisguiseAsColor)
	owner:SetSolid(self.UndisguiseAsSolid)
	owner:SetAllowFullRotation(self.UndisguiseAsFullRotation) // up/down rotation
	owner:SetBloodColor(self.UndisguiseAsBloodColor)
	
	// Revert to old physics
	ophysobj:SetMass(self.UndisguiseAsMass)
	self:UpdateHealth(100)
	
	// Hull reset
	owner:ResetHull()
{'fraction_non_alphanumeric': 0.11174926156875616, 'fraction_numerical': 0.005743354118805382, 'mean_word_length': 4.374338624338624, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1053616', 'n_tokens_mistral': 4459, 'n_tokens_neox': 4201, 'n_words': 1135}