Mirror of 1.4.7 from Lovers Lab

This commit is contained in:
ghostclinic3YTB 2023-04-03 21:47:48 -04:00
parent 161133e4e1
commit 9a3d9f4185
607 changed files with 11263 additions and 1309 deletions

View file

@ -1,14 +1,12 @@
using System;
using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using Verse;
using HarmonyLib;
using System.Reflection;
//using AlienRace;
using UnityEngine;
using rjw;
using System.Reflection;
using Verse;
namespace SizedApparel
{
@ -214,6 +212,19 @@ namespace SizedApparel
}
public enum ColorMode
{
Skin, Hair
}
//Def for Hediff Graphic color options or else.
public class SizedApparelHeddifDef : Def
{
public HediffDef hediffDef;
//public string hediffDefName;
}
//Def per graphic(texture)
public class SizedApparelBodyPartGraphicDef : Def
{
@ -222,7 +233,6 @@ namespace SizedApparel
public Vector2 pivot = new Vector2(0.5f, 0.5f); // custom pivot of texture. UV. not pixel
//public Dictionary<string, BodyPartPoint> points = new Dictionary<string, BodyPartPoint>();
//public Dictionary<string, BodyPartSpline> splines = new Dictionary<string, BodyPartSpline>();
}
//Def per BodyParts
@ -237,9 +247,14 @@ namespace SizedApparel
{
static MethodInfo overrideMatMethod = AccessTools.Method(typeof(PawnRenderer), "OverrideMaterialIfNeeded");
public SizedApparelBodyPart(Pawn pawn, string bodyPartName, SizedApparelBodyPartOf bodyPartOf, string defaultHediffName, bool isBreast, bool isOverlay , string customPathName = null, SizedApparelBodyPartColorOf colorOf = SizedApparelBodyPartColorOf.Skin)
public bool AutoOffsetForFurCoveredBody = true;
public SizedApparelBodyPart(Pawn pawn, ApparelRecorderComp apparelRecorderComp, string bodyPartName, SizedApparelBodyPartOf bodyPartOf, string defaultHediffName, bool isBreast, bool isOverlay , string customPathName = null, SizedApparelBodyPartColorOf colorOf = SizedApparelBodyPartColorOf.Skin)
{
this.pawn = pawn; //owner
this.apparelRecorderCompCache = apparelRecorderComp; //for reduce GetComp Call; if it is null, it will try to get pawn's comp.
this.bodyPartName = bodyPartName;
this.def = DefDatabase<SizedApparelBodyPartDef>.AllDefs.FirstOrDefault(b => b.defName == bodyPartName);
@ -268,6 +283,8 @@ namespace SizedApparel
public SizedApparelBodyPartDef def;
public Pawn pawn;
public ApparelRecorderComp apparelRecorderCompCache; // for reduce getComp call;
public string bodyPartName; //breast, penis, belly, pubichair... etc. just name. not like architech something
public string customPath = null;
public SizedApparelBodyPartOf bodyPartOf = SizedApparelBodyPartOf.None;
@ -280,6 +297,8 @@ namespace SizedApparel
public bool isVisible = true;
public int lastPoseTick = -1;
public SizedApparelBodyPartColorOf colorType = SizedApparelBodyPartColorOf.Skin;
public Color? customColorOne;
public Color? customColorTwo;
@ -306,9 +325,15 @@ namespace SizedApparel
{
if (customPose == newPose)
return;
if(SizedApparelSettings.Debug)
Log.Message("[SizedApparel] Setting Custom Pose : " + newPose);
customPose = newPose;
if (autoUpdate)
{
this.UpdateGraphic();
this.lastPoseTick = Find.TickManager.TicksGame;
}
if(autoSetPawnGraphicDirty)
{
if (pawn == null)
@ -318,7 +343,7 @@ namespace SizedApparel
}
}
public bool CheckCanPose(string targetPose, bool checkApparels, bool mustMatchSize)
public bool CheckCanPose(string targetPose, bool checkApparels, bool checkBodyParts, bool mustMatchSize)
{
if (checkApparels)
{
@ -331,6 +356,9 @@ namespace SizedApparel
if (agr.sourceApparel.def.apparel.tags.Any(s => s.ToLower() == "SizedApparel_IgnorePose".ToLower()))
continue;
*/
//Only Check Torso Apparel Only
if (!agr.sourceApparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso))
continue;
string originalPath = SizedApparelsDatabase.GetSupportedApparelOriginalPath(agr.graphic.path);
if (originalPath == null)
@ -338,17 +366,23 @@ namespace SizedApparel
int outInt = -1;
float outFloat = -1;
SizedApparelsDatabase.SizedApparelDatabaseKey key = new SizedApparelsDatabase.SizedApparelDatabaseKey(originalPath,pawn.def.defName,pawn.story?.bodyType?.defName, currentHediffName, Math.Min(currentSeverityInt, cappedSeverityInt), false, targetPose);
SizedApparelsDatabase.SizedApparelDatabaseKey key = new SizedApparelsDatabase.SizedApparelDatabaseKey(originalPath,pawn.def.defName,pawn.story?.bodyType?.defName, pawn.gender, currentHediffName, Math.Min(currentSeverityInt, cappedSeverityInt), false, targetPose);
if (SizedApparelSettings.useGenderSpecificTexture)
key.gender = Gender.None;
var result = SizedApparelsDatabase.GetSupportedApparelSizedPath(key, out outInt, out outFloat);
if (!result.isCustomPose)
return false;
}
}
Graphic graphic = GetBodyPartGraphics(false, mustMatchSize, targetPose);
Graphic graphicH = GetBodyPartGraphics(true, mustMatchSize, targetPose);
if (graphic != null || graphicH != null)
return true;
return false;
if (checkBodyParts)
{
Graphic graphic = GetBodyPartGraphics(false, mustMatchSize, targetPose);
Graphic graphicH = GetBodyPartGraphics(true, mustMatchSize, targetPose);
if (graphic != null || graphicH != null)
return true;
return false;
}
return true;
}
@ -378,6 +412,7 @@ namespace SizedApparel
public float depthOffset = 0f;
//0.008f
public float depthOffsetEast = 0.008f;
public float depthOffsetWest = 0.008f;
public float depthOffsetSouth = 0.008f;
@ -411,9 +446,9 @@ namespace SizedApparel
outPoints = null;
return null;
}
var comp = pawn.TryGetComp<ApparelRecorderComp>();
var comp = apparelRecorderCompCache;
if (comp == null)
comp = pawn.GetComp<ApparelRecorderComp>();
if (comp == null)
{
outPoints = null;
@ -421,7 +456,7 @@ namespace SizedApparel
}
var key = new SizedApparelsDatabase.BodyPartDatabaseKey(pawn.def.defName, pawn.story?.bodyType?.defName, currentHediffName, customPath==null?bodyPartName: customPath, Math.Min(currentSeverityInt, cappedSeverityInt), isHorny, poseOverride==null?customPose:poseOverride, variationOverride==null?variation: variationOverride);
var key = new SizedApparelsDatabase.BodyPartDatabaseKey(pawn.def.defName, pawn.story?.bodyType?.defName, currentHediffName, customPath==null?bodyPartName: customPath, pawn.gender, Math.Min(currentSeverityInt, cappedSeverityInt), isHorny, poseOverride==null?customPose:poseOverride, variationOverride==null?variation: variationOverride);
var result = SizedApparelsDatabase.GetSupportedBodyPartPath(key, isBreast, customPath == null ? bodyPartName : customPath, defaultHediffName);
if (mustMatchSize)
@ -503,24 +538,52 @@ namespace SizedApparel
if (pawn == null)
return;
if (bodyMesh == null)
{
if (SizedApparelSettings.Debug)
Log.Warning("[SizedApparel] DrawBodyParts But Null Body Mesh! : " + pawn.Name);
return;
}
PawnRenderer pawnRenderer = pawn.Drawer.renderer;
Shader shader = ShaderDatabase.CutoutComplex;
Color drawColor1 = Color.white;
Color drawColor2 = Color.white;
bool forceWriteZ = true;
if(colorType == SizedApparelBodyPartColorOf.Skin)
bool HasFurSkin = false;
//Furskin Check
if (pawn.Drawer.renderer.graphics.furCoveredGraphic != null)
{
HasFurSkin = true;
}
if (colorType == SizedApparelBodyPartColorOf.Skin)
{
forceWriteZ = true;
if (bodyDrawType == RotDrawMode.Fresh)
{
if (HasFurSkin)
{
shader = pawn.Drawer.renderer.graphics.furCoveredGraphic.Shader;
if (!ShaderUtility.SupportsMaskTex(shader))
shader = ShaderDatabase.CutoutSkinOverlay;
shader = pawnRenderer.graphics.furCoveredGraphic.Shader;
drawColor1 = pawnRenderer.graphics.furCoveredGraphic.Color;
drawColor2 = pawnRenderer.graphics.furCoveredGraphic.ColorTwo;
}
else
{
shader = pawn.Drawer.renderer.graphics.nakedGraphic.Shader;
if (!ShaderUtility.SupportsMaskTex(shader))
shader = ShaderDatabase.CutoutSkinOverlay;
drawColor1 = pawnRenderer.graphics.nakedGraphic.Color;
drawColor2 = pawnRenderer.graphics.nakedGraphic.ColorTwo;
}
shader = pawn.Drawer.renderer.graphics.nakedGraphic.Shader;
if (!ShaderUtility.SupportsMaskTex(shader))
shader = ShaderDatabase.CutoutSkinOverlay;
drawColor1 = pawn.Drawer.renderer.graphics.nakedGraphic.Color;
drawColor2 = pawn.Drawer.renderer.graphics.nakedGraphic.ColorTwo;
}
else if (bodyDrawType == RotDrawMode.Rotting)
{
@ -528,16 +591,18 @@ namespace SizedApparel
shader = pawn.Drawer.renderer.graphics.rottingGraphic.Shader;
if (!ShaderUtility.SupportsMaskTex(shader))
shader = ShaderDatabase.CutoutSkinOverlay;
drawColor1 = pawn.Drawer.renderer.graphics.rottingGraphic.Color;
drawColor2 = pawn.Drawer.renderer.graphics.nakedGraphic.ColorTwo;
drawColor1 = pawnRenderer.graphics.rottingGraphic.Color;
drawColor2 = pawnRenderer.graphics.nakedGraphic.ColorTwo;
}
}
else if (colorType == SizedApparelBodyPartColorOf.Hair)
{
forceWriteZ = false;
shader = ShaderDatabase.Transparent;
if(pawn.story != null)
drawColor1 = pawn.story.hairColor;
drawColor1 = pawn.story.HairColor;
}
else if (colorType == SizedApparelBodyPartColorOf.Custom)
{
@ -560,6 +625,11 @@ namespace SizedApparel
Quaternion quaternion = Quaternion.AngleAxis(angle + rotation, Vector3.up);
Vector3 vector = rootLoc;
if (this.pawn.ageTracker.CurLifeStage.bodyDrawOffset != null)
{
vector += this.pawn.ageTracker.CurLifeStage.bodyDrawOffset.Value;
}
Rot4 targetRot = facing;
if (rotOverride != null)
targetRot = rotOverride.Value;
@ -594,6 +664,8 @@ namespace SizedApparel
}
Graphic graphic = null;
if (SizedApparelUtility.IsHorny(pawn))
graphic = bodyPartGraphicHorny;
@ -603,13 +675,28 @@ namespace SizedApparel
if (graphic == null)
return;
//ForFurskinOffset
if(bodyDrawType == RotDrawMode.Fresh && HasFurSkin && AutoOffsetForFurCoveredBody)
{
//vector.y += 0.009187258f; //in PawnRenderer, it adds 0.009187258f.
//graphic.maskPath does error? need to check
// worn fur body and naked fur body has different offsets... wtf
//TODO Need to Fix
}
Material mat;
if (!flags.FlagSet(PawnRenderFlags.Cache)&&!isOverlay&& forceWriteZ)
{
graphic = graphic.GetColoredVersion(ShaderDatabase.Cutout, drawColor1, drawColor2);
graphic = graphic.GetColoredVersion(ShaderDatabase.Cutout, drawColor1, drawColor2); // ShaderDatabase.Cutout
mat = flags.FlagSet(PawnRenderFlags.Cache) ? graphic.MatAt(targetRot) : (Material)overrideMatMethod.Invoke(pawnRenderer, new object[] { graphic.MatAt(facing), pawn, flags.FlagSet(PawnRenderFlags.Portrait) });
GenDraw.DrawMeshNowOrLater(bodyMesh, vector, quaternion, mat, flags.FlagSet(PawnRenderFlags.DrawNow)); // draw for writeZ data to solve shadow issue
}
graphic = graphic.GetColoredVersion(shader, drawColor1, drawColor2);
vector.y += 0.00001f;
mat = flags.FlagSet(PawnRenderFlags.Cache) ? graphic.MatAt(targetRot) : (Material)overrideMatMethod.Invoke(pawnRenderer, new object[] { graphic.MatAt(facing), pawn, flags.FlagSet(PawnRenderFlags.Portrait) });