Skip to content

Instantly share code, notes, and snippets.

@ronyx69
Last active January 21, 2019 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronyx69/f27a35f5ccbb04748700fdacc39a33c0 to your computer and use it in GitHub Desktop.
Save ronyx69/f27a35f5ccbb04748700fdacc39a33c0 to your computer and use it in GitHub Desktop.
Source code for the Flag Params mod.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICities;
using UnityEngine;
namespace FlagParams
{
public class FlagParamsMod : LoadingExtensionBase, IUserMod
{
public string Name => "Flag Params";
public string Description => "Loads flag shader parameters.";
public override void OnLevelLoaded(LoadMode mode)
{
base.OnLevelLoaded(mode);
ApplyParams();
}
public override void OnLevelUnloading()
{
base.OnLevelUnloading();
}
private void ApplyParams()
{
for (uint i = 0; i < PrefabCollection<PropInfo>.LoadedCount(); i++)
{
var prefab = PrefabCollection<PropInfo>.GetLoaded(i);
if (prefab == null) continue;
if (prefab.m_mesh.name.Contains("FlagShader ") == true)
{
string[] floats = prefab.m_mesh.name.Split(' ');
Vector4 a = new Vector4(Convert.ToSingle(floats[1]), Convert.ToSingle(floats[2]), Convert.ToSingle(floats[3]), 0f);
Vector4 p = new Vector4(Convert.ToSingle(floats[4]), Convert.ToSingle(floats[5]), Convert.ToSingle(floats[6]), 0f);
Vector4 t = new Vector4(Convert.ToSingle(floats[7]), Convert.ToSingle(floats[8]), Convert.ToSingle(floats[9]), Convert.ToSingle(floats[10]));
prefab.m_material.SetVector("_RollParams3", t);
prefab.m_material.SetVector("_RollLocation0", p);
prefab.m_material.SetVector("_RollParams0", a);
if (prefab.m_lodMaterial)
{
prefab.m_lodMaterial.SetVector("_RollParams3", t);
prefab.m_lodMaterial.SetVector("_RollLocation0", p);
prefab.m_lodMaterial.SetVector("_RollParams0", a);
}
if (prefab.m_lodMaterialCombined)
{
prefab.m_lodMaterialCombined.SetVector("_RollParams3", t);
prefab.m_lodMaterialCombined.SetVector("_RollLocation0", p);
prefab.m_lodMaterialCombined.SetVector("_RollParams0", a);
}
}
}
for (uint i = 0; i < PrefabCollection<VehicleInfo>.LoadedCount(); i++)
{
var prefab = PrefabCollection<VehicleInfo>.GetLoaded(i);
if (prefab == null) continue;
if (prefab.m_subMeshes == null) continue;
if (prefab.m_subMeshes.Length == 0) continue;
for (uint j = 0; j < prefab.m_subMeshes.Length; j++)
{
if (prefab.m_subMeshes[j].m_subInfo == null) continue;
if (prefab.m_subMeshes[j].m_subInfo.m_mesh == null) continue;
if (prefab.m_subMeshes[j].m_subInfo.m_mesh.name.Contains("FlagShader ") == true)
{
string[] floats = prefab.m_subMeshes[j].m_subInfo.m_mesh.name.Split(' ');
Vector4 a = new Vector4(Convert.ToSingle(floats[1]), Convert.ToSingle(floats[2]), Convert.ToSingle(floats[3]), 0f);
Vector4 p = new Vector4(Convert.ToSingle(floats[4]), Convert.ToSingle(floats[5]), Convert.ToSingle(floats[6]), 0f);
Vector4 t = new Vector4(Convert.ToSingle(floats[7]), Convert.ToSingle(floats[8]), Convert.ToSingle(floats[9]), Convert.ToSingle(floats[10]));
prefab.m_subMeshes[j].m_subInfo.m_material.SetVector("_RollParams3", t);
prefab.m_subMeshes[j].m_subInfo.m_material.SetVector("_RollLocation0", p);
prefab.m_subMeshes[j].m_subInfo.m_material.SetVector("_RollParams0", a);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment