Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
aedenthorn committed Jun 20, 2020
1 parent af3f5f9 commit 9d04a96
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 72 deletions.
Binary file modified .vs/PortiaMods/v16/.suo
Binary file not shown.
56 changes: 25 additions & 31 deletions CookingMachine/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ namespace CookingMachine
public static class Main
{
public static bool enabled;
private static bool isDebug = true;
private static bool isDebug = false;
private static List<int> crash;
private static CompoundItemData templateData;

public static void Dbgl(string str = "", bool pref = true)
{
Expand All @@ -34,6 +35,12 @@ private static void Load(UnityModManager.ModEntry modEntry)
{
settings = Settings.Load<Settings>(modEntry);

SqliteDataReader reader = LocalDb.cur.ReadFullTable("Synthesis_table ");
var sourceData = DbReader.Read<CompoundItemData>(reader, 20);

templateData = sourceData.Find((CompoundItemData c) => c.ItemID == 2000046);


modEntry.OnToggle = OnToggle;
modEntry.OnGUI = OnGUI;
modEntry.OnSaveGUI = OnSaveGUI;
Expand Down Expand Up @@ -72,6 +79,7 @@ static class AutomataMachineMenuCtr_1
{
static void Postfix(ref CompoundItem[] __result)
{

int start = 5000;
int start2 = 5001000;

Expand All @@ -83,60 +91,46 @@ static void Postfix(ref CompoundItem[] __result)
Dbgl("missing list");
return;
}
Dbgl("getting cid");

SqliteDataReader reader = LocalDb.cur.ReadFullTable("Synthesis_table ");
var sourceData = DbReader.Read<CompoundItemData>(reader, 20);

CompoundItemData cidd = sourceData.Find((CompoundItemData c) => c.ItemID == 2000046);

Dbgl("getting list");
foreach (CookBookData food in cookList)
{
if (food != null && food.like)
{
Dbgl("got food");
cidd.NameID = Module<ItemDataMgr>.Self.GetItemNameId(food.foodId);
cidd.ItemID = food.foodId;
Dbgl("food " + food.foodId);
Dbgl("menu list length " + food.menuList.Count);
templateData.NameID = Module<ItemDataMgr>.Self.GetItemNameId(food.foodId);
templateData.ItemID = food.foodId;
foreach (CookMatData cmd in food.menuList)
{
Dbgl("matdic length " + cmd.matDic.Count);
cidd.ID = start++;
cidd.BookId = start2++;
cidd.RequireItem1 = cmd.matDic.Keys.ToList()[0];
cidd.RequireItemNum1 = cmd.matDic[cmd.matDic.Keys.ToList()[0]];
Dbgl($"item1 {cidd.RequireItem1} count {cidd.RequireItemNum1}");
templateData.ID = start++;
templateData.BookId = start2++;
templateData.RequireItem1 = cmd.matDic.Keys.ToList()[0];
templateData.RequireItemNum1 = cmd.matDic[cmd.matDic.Keys.ToList()[0]];
if (cmd.matDic.Count > 1)
{
cidd.RequireItem2 = cmd.matDic.Keys.ToList()[1];
cidd.RequireItemNum2 = cmd.matDic[cmd.matDic.Keys.ToList()[1]];
Dbgl($"item2 {cidd.RequireItem2} count {cidd.RequireItemNum2}");
templateData.RequireItem2 = cmd.matDic.Keys.ToList()[1];
templateData.RequireItemNum2 = cmd.matDic[cmd.matDic.Keys.ToList()[1]];
if (cmd.matDic.Count > 2)
{
cidd.RequireItem3 = cmd.matDic.Keys.ToList()[2];
cidd.RequireItemNum3 = cmd.matDic[cmd.matDic.Keys.ToList()[2]];
Dbgl($"item3 {cidd.RequireItem3} count {cidd.RequireItemNum3}");
templateData.RequireItem3 = cmd.matDic.Keys.ToList()[2];
templateData.RequireItemNum3 = cmd.matDic[cmd.matDic.Keys.ToList()[2]];
}
else
{
cidd.RequireItem3 = 0;
cidd.RequireItemNum3 = 0;
templateData.RequireItem3 = 0;
templateData.RequireItemNum3 = 0;
}
}
else
{
cidd.RequireItem2 = 0;
cidd.RequireItemNum2 = 0;
templateData.RequireItem2 = 0;
templateData.RequireItemNum2 = 0;
}
newList.Add(new CompoundItem(cidd));
newList.Add(new CompoundItem(templateData));
}
}
}
Dbgl("list length" + __result.Length);

__result = newList.ToArray();
Dbgl("list length" + __result.Length);
}
}

Expand Down
10 changes: 2 additions & 8 deletions CustomTextures/Main.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Harmony12;
using Pathea;
using Pathea.ModuleNs;
using System.Reflection;
using UnityEngine;
using UnityEngine.SceneManagement;
Expand Down Expand Up @@ -77,14 +79,6 @@ private static void ChangeScene(Scene arg0, Scene arg1)
}
FixSceneTextures(arg1);

if(arg1.name == "Main")
{
FixWorkshopTextures();
}
else if(arg1.name == "PlayerHome")
{
FixHomeTextures();
}
}

}
Expand Down
101 changes: 99 additions & 2 deletions CustomTextures/Methods.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Harmony12;
using Pathea;
using Pathea.ActorNs;
using Pathea.Expression;
using Pathea.HomeNs;
using Pathea.ModuleNs;
using Pathea.NpcAppearNs;
Expand Down Expand Up @@ -177,6 +178,38 @@ private static void FixSceneTextures(Scene arg1)
{
FixOneTexture(obj);
}

if (Module<Player>.Self != null && Module<Player>.Self.actor != null)
{
FixOneTexture(Module<Player>.Self.actor.gameObject);

BlinkController bc = (BlinkController) typeof(Actor).GetField("blinkController", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Module<Player>.Self.actor);
if(bc != null)
{
SkinnedMeshRenderer mr = (SkinnedMeshRenderer)typeof(BlinkController).GetField("_mesh", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(bc);
if(mr != null)
{
string name = mr.name;
if (customTexturesMisc.ContainsKey(name) && mr.material && mr.material.HasProperty("_MainTex") && mr.material.mainTexture != null)
{
Dbgl($"Changing texture for {name}");
Texture2D tex = customTexturesMisc[name];
tex.name = $"{name}.png";
mr.material.mainTexture = tex;
}
}
}
}

if (arg1.name == "Main")
{
FixWorkshopTextures();
}
else if (arg1.name == "PlayerHome")
{
FixHomeTextures();
}

}

private static void FixOneTexture(GameObject go)
Expand All @@ -195,6 +228,18 @@ private static void FixOneTexture(GameObject go)
mr.material.mainTexture = tex;
}
}
SkinnedMeshRenderer[] smrs = go.GetComponentsInChildren<SkinnedMeshRenderer>();
foreach (SkinnedMeshRenderer mr in smrs)
{
string name = mr.name;
if (customTexturesMisc.ContainsKey(name) && mr.material && mr.material.HasProperty("_MainTex") && mr.material.mainTexture != null)
{
Dbgl($"Changing texture for {name}");
Texture2D tex = customTexturesMisc[name];
tex.name = $"{name}.png";
mr.material.mainTexture = tex;
}
}
}

private static void DumpObjectNames()
Expand All @@ -206,10 +251,62 @@ private static void DumpObjectNames()
Dbgl("scene is null");
return;
}

string names = "";
List<string> meshTextures = new List<string>();

string names = "";
if (Module<Player>.Self != null && Module<Player>.Self.actor != null)
{
GameObject player = Module<Player>.Self.actor.gameObject;
names += $"Player actor mesh and texture names:\r\n\r\n\t";


MeshRenderer[] mrs = player.GetComponentsInChildren<MeshRenderer>();

foreach (MeshRenderer mr in mrs)
{
if (mr.material && mr.material.HasProperty("_MainTex") && mr.material.mainTexture != null)
{
string mt = $"mesh name: {mr.name} texture name: {mr.material.mainTexture.name}";
if (!meshTextures.Contains(mt))
{
meshTextures.Add(mt);
}

}
}

SkinnedMeshRenderer[] smrs = player.GetComponentsInChildren<SkinnedMeshRenderer>();

foreach (SkinnedMeshRenderer mr in smrs)
{
if (mr.material && mr.material.HasProperty("_MainTex") && mr.material.mainTexture != null)
{
string mt = $"smesh name: {mr.name} texture name: {mr.material.mainTexture.name}";
if (!meshTextures.Contains(mt))
{
meshTextures.Add(mt);
}

}
}

BlinkController bc = (BlinkController)typeof(Actor).GetField("blinkController", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Module<Player>.Self.actor);
if (bc != null)
{
SkinnedMeshRenderer smr = (SkinnedMeshRenderer)typeof(BlinkController).GetField("_mesh", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(bc);
if (smr != null && smr.material && smr.material.HasProperty("_MainTex") && smr.material.mainTexture != null)
{
string mt = $"blink mesh name: {smr.name} texture name: {smr.material.mainTexture.name}";
if (!meshTextures.Contains(mt))
{
meshTextures.Add(mt);
}
}
}

names += string.Join("\r\n\t", meshTextures.ToArray()) + "\r\n\r\n";
meshTextures.Clear();
}

names += $"DLC actor mesh and texture names:\r\n\r\n\t";

Expand Down
24 changes: 20 additions & 4 deletions CustomTextures/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static void Prefix(NpcAppear __instance, List<NpcAppearUnit> npcAppearUn
[HarmonyPatch(typeof(AppearTarget), "BuildMesh", new Type[] { typeof(List<AppearUnit>), typeof(AppearData), typeof(AppearUnit), typeof(string) })]
static class BuildMesh1_Patch
{
static void Prefix(AppearTarget __instance, AppearData appearData, ref List<AppearUnit> units)
static void Prefix(ref List<AppearUnit> units)
{
//Dbgl($"Building player mesh");

Expand All @@ -97,13 +97,29 @@ static void Prefix(AppearTarget __instance, AppearData appearData, ref List<Appe
{
string name = units[i].name;
Dbgl($"appear part name: {name}");
if (customTexturesMisc.ContainsKey(name))
if (units[i].Smr != null)
{
Dbgl($"Changing texture for {name}");
units[i].Smr.material.mainTexture = customTexturesMisc[name];

if (units[i].Smr.material.HasProperty("_MainTex") && customTexturesMisc.ContainsKey(name))
{
Dbgl($"Changing texture for {name}");
units[i].Smr.material.mainTexture = customTexturesMisc[name];
}
}
}
}
static void Postfix(ref SkinnedMeshRenderer __result)
{
//Dbgl($"Building player mesh");

if (!enabled)
return;
for(int i = 0; i < __result.materials.Length; i++)
{
__result.materials[i].mainTexture = customTexturesMisc["AppearUnit_Linda_Test"];
}
__result.material.mainTexture = customTexturesMisc["AppearUnit_Linda_Test"];
}
}


Expand Down
4 changes: 2 additions & 2 deletions PostProcessing/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ private static void OnGUI(UnityModManager.ModEntry modEntry)

}

/*
GUILayout.Space(10f);

settings.customAA = GUILayout.Toggle(settings.customAA, "<b>Use Custom Anti-Aliasing</b>", new GUILayoutOption[0]);
if (settings.customAA)
{
Expand Down Expand Up @@ -550,7 +550,7 @@ private static void OnGUI(UnityModManager.ModEntry modEntry)
GUILayout.EndHorizontal();
}

*/
GUILayout.Space(20f);

GUILayout.EndVertical();
Expand Down
Loading

0 comments on commit 9d04a96

Please sign in to comment.