-- Copyright ©2022 by Todd Hundersmarck (ThundR)
-- All Rights Reserved
THShip = {} local THShip_mt = Class(THShip, Ship) local dynamicIds = {} local function runScript() local globalEnv = g_thMain:getGlobalEnv() globalEnv.THShip = THShip g_thMain:hookFunction("Ship", "new", THShip, nil, false) g_thMain:hookFunction("Ship", "update", THShip) g_thMain:hookFunction("Ship", "update", THShip) end function THShip:onCreate(id, ...) if entityExists(id) then return THShip:superClass().onCreate(self, id, ...) end end function THShip.hook_new(superFunc, id, ...) local object, ra,rb,rc,rd,re = superFunc(id, ...) if object ~= nil then object.thId = id dynamicIds[id] = true end return object, ra,rb,rc,rd,re end function THShip:hook_update(superFunc, dt, ...) local id = self.thId if entityExists(id) then local globalEnv = g_thMain:getGlobalEnv() local setTranslation_orig = globalEnv.setTranslation local setRotation_orig = globalEnv.setRotation if dynamicIds[id] then globalEnv.setTranslation = globalEnv.setWorldTranslation globalEnv.setRotation = globalEnv.setWorldRotation end local ra,rb,rc,rd,re = superFunc(self, dt, ...) globalEnv.setTranslation = setTranslation_orig globalEnv.setRotation = setRotation_orig return ra,rb,rc,rd,re end end function THShip:hook_delete(superFunc, ...) local id = self.thId if id ~= nil then dynamicIds[id] = nil end g_currentMission:removeUpdateable(self) return superFunc(self, ...) end runScript()