Example #1
0
        void setCarVisuals(CarVisuals visuals, GameObject car)
        {
            if (visuals == null)
            {
                ErrorList.add("Can't find the CarVisuals component on the base car");
                return;
            }

            var skinned = car.GetComponentInChildren <SkinnedMeshRenderer>();

            MakeMeshSkinned(skinned);
            visuals.carBodyRenderer_ = skinned;

            var boostJets    = new List <JetFlame>();
            var wingJets     = new List <JetFlame>();
            var rotationJets = new List <JetFlame>();

            PlaceJets(car, boostJets, wingJets, rotationJets);
            visuals.boostJetFlames_    = boostJets.ToArray();
            visuals.wingJetFlames_     = wingJets.ToArray();
            visuals.rotationJetFlames_ = rotationJets.ToArray();
            visuals.driverPosition_    = findCarDriver(car.transform);

            placeCarWheelsVisuals(visuals, car);
        }
Example #2
0
        void removeOldCar(GameObject obj)
        {
            List <GameObject> wheelsToRemove = new List <GameObject>();

            for (int i = 0; i < obj.transform.childCount; i++)
            {
                var c = obj.transform.GetChild(i).gameObject;
                if (c.name.ToLower().Contains("wheel"))
                {
                    wheelsToRemove.Add(c);
                }
            }
            if (wheelsToRemove.Count != 4)
            {
                ErrorList.add("Found " + wheelsToRemove.Count + " wheels on base prefabs, expected 4");
            }

            var refractor = obj.transform.Find("Refractor");

            if (refractor == null)
            {
                ErrorList.add("Can't find the Refractor object on the base car prefab");
                return;
            }
            GameObject.Destroy(refractor.gameObject);
            foreach (var w in wheelsToRemove)
            {
                GameObject.Destroy(w);
            }
        }
Example #3
0
        void getBaseCar()
        {
            var prefab = G.Sys.ProfileManager_.carInfos_[0].prefabs_.carPrefab_;

            if (prefab == null)
            {
                ErrorList.add("Can't find the refractor base car prefab");
                return;
            }
            baseCar       = prefab;
            defaultColors = G.Sys.ProfileManager_.carInfos_[0].colors_;
        }
Example #4
0
        void replaceMaterials(Renderer r)
        {
            string[] matNames = new string[r.materials.Length];
            for (int i = 0; i < matNames.Length; i++)
            {
                matNames[i] = "wheel";
            }
            List <MaterialPropertyExport>[] matProperties = new List <MaterialPropertyExport> [r.materials.Length];
            for (int i = 0; i < matProperties.Length; i++)
            {
                matProperties[i] = new List <MaterialPropertyExport>();
            }

            fillMaterialInfos(r, matNames, matProperties);

            var materials = r.materials.ToArray();

            for (int i = 0; i < r.materials.Length; i++)
            {
                MaterialInfos matInfo = null;
                if (!m_infos.materials.TryGetValue(matNames[i], out matInfo))
                {
                    ErrorList.add("Can't find the material " + matNames[i] + " on " + r.gameObject.FullName());
                    continue;
                }
                if (matInfo == null || matInfo.material == null)
                {
                    continue;
                }
                Material mat = UnityEngine.Object.Instantiate(matInfo.material);
                if (matInfo.diffuseIndex >= 0)
                {
                    mat.SetTexture(matInfo.diffuseIndex, r.materials[i].GetTexture("_MainTex"));
                }
                if (matInfo.normalIndex >= 0)
                {
                    mat.SetTexture(matInfo.normalIndex, r.materials[i].GetTexture("_BumpMap"));
                }
                if (matInfo.emitIndex >= 0)
                {
                    mat.SetTexture(matInfo.emitIndex, r.materials[i].GetTexture("_EmissionMap"));
                }

                foreach (var p in matProperties[i])
                {
                    copyMaterialProperty(r.materials[i], mat, p);
                }

                materials[i] = mat;
            }
            r.materials = materials;
        }
Example #5
0
        void getMaterials()
        {
            List <MaterialPropertyInfo> materialsNames = new List <MaterialPropertyInfo>
            {
                new MaterialPropertyInfo("Custom/LaserCut/CarPaint", "carpaint", 5, -1, -1),
                new MaterialPropertyInfo("Custom/LaserCut/CarWindow", "carwindow", -1, 218, 219),
                new MaterialPropertyInfo("Custom/Reflective/Bump Glow LaserCut", "wheel", 5, 218, 255),
                new MaterialPropertyInfo("Custom/LaserCut/CarPaintBump", "carpaintbump", 5, 218, -1),
                new MaterialPropertyInfo("Custom/Reflective/Bump Glow Interceptor Special", "interceptor", 5, 218, 255),
                new MaterialPropertyInfo("Custom/LaserCut/CarWindowTrans2Sided", "transparentglow", -1, 218, 219)
            };

            foreach (var c in G.Sys.ProfileManager_.carInfos_)
            {
                var prefab = c.prefabs_.carPrefab_;
                foreach (var renderer in prefab.GetComponentsInChildren <Renderer>())
                {
                    foreach (var mat in renderer.materials)
                    {
                        foreach (var key in materialsNames)
                        {
                            if (materials.ContainsKey(key.name))
                            {
                                continue;
                            }
                            if (mat.shader.name == key.shaderName)
                            {
                                var m = new MaterialInfos();
                                m.material     = mat;
                                m.diffuseIndex = key.diffuseIndex;
                                m.normalIndex  = key.normalIndex;
                                m.emitIndex    = key.emitIndex;
                                materials.Add(key.name, m);
                            }
                        }
                    }
                }
            }

            foreach (var mat in materialsNames)
            {
                if (!materials.ContainsKey(mat.name))
                {
                    ErrorList.add("Can't find the material: " + mat.name + " - shader: " + mat.shaderName);
                }
            }

            materials.Add("donotreplace", new MaterialInfos());
        }
Example #6
0
        void setColorChanger(ColorChanger colorChanger, GameObject car)
        {
            if (colorChanger == null)
            {
                ErrorList.add("Can't find the ColorChanger component on the base car");
                return;
            }

            colorChanger.rendererChangers_ = new ColorChanger.RendererChanger[0];
            foreach (var r in car.GetComponentsInChildren <Renderer>())
            {
                replaceMaterials(r);
                if (colorChanger != null)
                {
                    addMaterialColorChanger(colorChanger, r.transform);
                }
            }
        }
Example #7
0
        public void Initialize(IManager manager, string ipcIdentifier)
        {
            try
            {
                var harmony = new Harmony("com.Larnin.CustomCar");

                harmony.PatchAll(Assembly.GetExecutingAssembly());
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.ToString());
            }

            //DebugShaderList.Exec();
            ShaderTool.Instanciate();
            //AudioPlayer.Init();

            try
            {
                CarInfos carInfos = new CarInfos();
                carInfos.collectInfos();
                CarBuilder builder = new CarBuilder();
                builder.createCars(carInfos);
            }
            catch (Exception e)
            {
                ErrorList.add("An error occured while trying to load cars assets");
                Console.Out.WriteLine(e.ToString());
            }

            ModdedCarsColors.LoadAll();

            //disable loging cars
            //LogCarPrefabs.logCars();

            Events.MainMenu.Initialized.Subscribe(data =>
            {
                if (ErrorList.haveErrors())
                {
                    ErrorList.show();
                }
            });
        }
Example #8
0
        void getJetsAndTrail()
        {
            if (baseCar == null)
            {
                return;
            }

            foreach (var j in baseCar.GetComponentsInChildren <JetFlame>())
            {
                var name = j.gameObject.name;
                if (name == "BoostJetFlameCenter")
                {
                    boostJet = j.gameObject;
                }
                else if (name == "JetFlameBackLeft")
                {
                    rotationJet = j.gameObject;
                }
                else if (name == "WingJetFlameLeft1")
                {
                    wingJet = j.gameObject;
                }
            }
            wingTrail = baseCar.GetComponentInChildren <WingTrail>().gameObject;

            if (boostJet == null)
            {
                ErrorList.add("No valid BoostJet found on Refractor");
            }
            if (rotationJet == null)
            {
                ErrorList.add("No valid RotationJet found on Refractor");
            }
            if (wingJet == null)
            {
                ErrorList.add("No valid WingJet found on Refractor");
            }
            if (wingTrail == null)
            {
                ErrorList.add("No valid WingTrail found on Refractor");
            }
        }
Example #9
0
        List <GameObject> loadAssetsBundle()
        {
            var dirStr = Path.Combine(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location), Defaults.PrivateAssetsDirectory);
            var files  = Directory.GetFiles(dirStr);

            List <GameObject> cars = new List <GameObject>();

            foreach (var f in files)
            {
                var index = f.LastIndexOf('/');
                if (index < 0)
                {
                    index = f.LastIndexOf('\\');
                }
                var name  = f.Substring(index + 1);
                var asset = new Assets(name);

                GameObject car = null;
                foreach (var n in asset.Bundle.GetAllAssetNames())
                {
                    if (car == null && n.EndsWith(".prefab"))
                    {
                        car = asset.Bundle.LoadAsset <GameObject>(n);
                        break;
                    }
                }

                if (car == null)
                {
                    ErrorList.add("Can't find a prefab in the asset bundle " + f);
                }
                else
                {
                    car.name = name;
                    cars.Add(car);
                }
            }

            return(cars);
        }
Example #10
0
        void MakeMeshSkinned(SkinnedMeshRenderer renderer)
        {
            var mesh = renderer.sharedMesh;

            if (mesh == null)
            {
                ErrorList.add("The mesh on " + renderer.gameObject.FullName() + " is null");
                return;
            }
            if (!mesh.isReadable)
            {
                ErrorList.add("Can't read the car mesh " + mesh.name + " on " + renderer.gameObject.FullName() + "You must allow reading on it's unity inspector !");
                return;
            }
            if (mesh.vertices.Length == mesh.boneWeights.Length)
            {
                return;
            }

            var bones = new BoneWeight[mesh.vertices.Length];

            for (int i = 0; i < bones.Length; i++)
            {
                bones[i].weight0 = 1;
            }
            mesh.boneWeights = bones;
            var t         = renderer.transform;
            var bindPoses = new Matrix4x4[1] {
                t.worldToLocalMatrix *renderer.transform.localToWorldMatrix
            };

            mesh.bindposes = bindPoses;
            renderer.bones = new Transform[1] {
                t
            };
        }
Example #11
0
        void addMaterialColorChanger(ColorChanger colorChanger, Transform t)
        {
            Renderer r = t.GetComponent <Renderer>();

            if (r == null)
            {
                return;
            }

            var uniformChangers = new List <ColorChanger.UniformChanger>();

            for (int i = 0; i < t.childCount; i++)
            {
                var o    = t.GetChild(i).gameObject;
                var name = o.name.ToLower();
                if (!name.StartsWith("#"))
                {
                    continue;
                }

                name = name.Remove(0, 1); //remove #

                var s = name.Split(';');
                if (s.Length == 0)
                {
                    continue;
                }
                if (!s[0].Contains("color"))
                {
                    continue;
                }
                if (s.Length != 6)
                {
                    ErrorList.add(s[0] + " property on " + t.gameObject.FullName() + " must have 5 arguments");
                    continue;
                }

                var uniformChanger = new ColorChanger.UniformChanger();
                int materialIndex  = 0;
                int.TryParse(s[1], out materialIndex);
                uniformChanger.materialIndex_ = materialIndex;
                uniformChanger.colorType_     = colorType(s[2]);
                uniformChanger.name_          = uniformName(s[3]);
                float multiplier = 0;
                float.TryParse(s[4], out multiplier);
                uniformChanger.mul_   = multiplier;
                uniformChanger.alpha_ = s[5].ToLower() == "true";

                uniformChangers.Add(uniformChanger);
            }

            if (uniformChangers.Count == 0)
            {
                return;
            }

            var renderChanger = new ColorChanger.RendererChanger();

            renderChanger.renderer_        = r;
            renderChanger.uniformChangers_ = uniformChangers.ToArray();

            var renders = colorChanger.rendererChangers_.ToList();

            renders.Add(renderChanger);
            colorChanger.rendererChangers_ = renders.ToArray();
        }
Example #12
0
        void fillMaterialInfos(Renderer r, string[] matNames, List <MaterialPropertyExport>[] matProperties)
        {
            int childCount = r.transform.childCount;

            for (int i = 0; i < childCount; i++)
            {
                var name = r.transform.GetChild(i).name.ToLower();
                if (!name.StartsWith("#"))
                {
                    continue;
                }
                name = name.Remove(0, 1);
                var s = name.Split(';');
                if (s.Length == 0)
                {
                    continue;
                }
                if (s[0].Contains("mat"))
                {
                    if (s.Length != 3)
                    {
                        ErrorList.add(s[0] + " property on " + r.gameObject.FullName() + " must have 2 arguments");
                        continue;
                    }
                    int index = 0;
                    if (!int.TryParse(s[1], out index))
                    {
                        ErrorList.add("First argument of " + s[0] + " on " + r.gameObject.FullName() + " property must be a number");
                        continue;
                    }
                    if (index < matNames.Length)
                    {
                        matNames[index] = s[2];
                    }
                }
                else if (s[0].Contains("export"))
                {
                    if (s.Length != 5)
                    {
                        ErrorList.add(s[0] + " property on " + r.gameObject.FullName() + " must have 4 arguments");
                        continue;
                    }
                    int index = 0;
                    if (!int.TryParse(s[1], out index))
                    {
                        ErrorList.add("First argument of " + s[0] + " on " + r.gameObject.FullName() + " property must be a number");
                        continue;
                    }
                    if (index >= matNames.Length)
                    {
                        continue;
                    }
                    MaterialPropertyExport p = new MaterialPropertyExport();
                    bool found = false;

                    foreach (MaterialPropertyExport.PropertyType pType in Enum.GetValues(typeof(MaterialPropertyExport.PropertyType)))
                    {
                        if (s[2] == pType.ToString().ToLower())
                        {
                            found  = true;
                            p.type = pType;
                            break;
                        }
                    }
                    if (!found)
                    {
                        ErrorList.add("The property " + s[2] + " on " + r.gameObject.FullName() + " is not valid");
                        continue;
                    }
                    if (!int.TryParse(s[3], out p.fromID))
                    {
                        p.fromName = s[3];
                    }
                    if (!int.TryParse(s[4], out p.toID))
                    {
                        p.toName = s[4];
                    }

                    matProperties[index].Add(p);
                }
            }
        }