|
| 1 | +#pragma once |
| 2 | +#include <fstream> |
| 3 | +#include <ostream> |
| 4 | +#include <streambuf> |
| 5 | +#include <sstream> |
| 6 | +#include "../LE1-SDK/SdkHeaders.h" |
| 7 | + |
| 8 | +/// <summary> |
| 9 | +/// Abstract class for creating custom HUDs similar to StreamingLevelsHUD |
| 10 | +/// </summary> |
| 11 | +class CustomHUD |
| 12 | +{ |
| 13 | +public: |
| 14 | + bool ShouldDraw = true; |
| 15 | + CustomHUD(LPSTR windowName = "MassEffect") |
| 16 | + { |
| 17 | + _windowName = windowName; |
| 18 | + } |
| 19 | + virtual void Update(UCanvas* canvas) |
| 20 | + { |
| 21 | + _canvas = canvas; |
| 22 | + } |
| 23 | + virtual void Draw() = 0; |
| 24 | + |
| 25 | +protected: |
| 26 | + UCanvas* _canvas; |
| 27 | + float textScale = 1.0f; |
| 28 | + float lineHeight = 12.0f; |
| 29 | + int yIndex; |
| 30 | + LPSTR _windowName; |
| 31 | + void SetTextScale() |
| 32 | + { |
| 33 | + HWND activeWindow = FindWindowA(NULL, _windowName); |
| 34 | + if (activeWindow) |
| 35 | + { |
| 36 | + RECT rcOwner; |
| 37 | + if (GetWindowRect(activeWindow, &rcOwner)) |
| 38 | + { |
| 39 | + long width = rcOwner.right - rcOwner.left; |
| 40 | + long height = rcOwner.bottom - rcOwner.top; |
| 41 | + |
| 42 | + if (width > 2560 && height > 1440) |
| 43 | + { |
| 44 | + textScale = 2.0f; |
| 45 | + } |
| 46 | + else if (width > 1920 && height > 1080) |
| 47 | + { |
| 48 | + textScale = 1.5f; |
| 49 | + } |
| 50 | + else |
| 51 | + { |
| 52 | + textScale = 1.0f; |
| 53 | + } |
| 54 | + lineHeight = 12.0f * textScale; |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + void RenderText(std::wstring msg, const float x, const float y, const char r, const char g, const char b, const float alpha) |
| 60 | + { |
| 61 | + if (_canvas) |
| 62 | + { |
| 63 | + _canvas->SetDrawColor(r, g, b, alpha * 255); |
| 64 | + _canvas->SetPos(x, y + 64); //+ is Y start. To prevent overlay on top of the power bar thing |
| 65 | + _canvas->DrawTextW(FString{ const_cast<wchar_t*>(msg.c_str()) }, 1, textScale, textScale, nullptr); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + void RenderTextLine(std::wstring msg, const char r, const char g, const char b, const float alpha) |
| 70 | + { |
| 71 | + RenderText(msg, 5, lineHeight * yIndex, r, g, b, alpha); |
| 72 | + yIndex++; |
| 73 | + } |
| 74 | + |
| 75 | + void RenderName(const wchar_t* label, FName name) |
| 76 | + { |
| 77 | + wchar_t output[512]; |
| 78 | + swprintf_s(output, 512, L"%s: %S", label, name.GetName()); |
| 79 | + RenderTextLine(output, 0, 255, 0, 1.0f); |
| 80 | + } |
| 81 | + |
| 82 | + void RenderString(const wchar_t* label, FString str) |
| 83 | + { |
| 84 | + wchar_t output[512]; |
| 85 | + swprintf_s(output, 512, L"%s: %s", label, str.Data); |
| 86 | + RenderTextLine(output, 0, 255, 0, 1.0f); |
| 87 | + } |
| 88 | + |
| 89 | + void RenderInt(const wchar_t* label, int value) |
| 90 | + { |
| 91 | + wchar_t output[512]; |
| 92 | + swprintf_s(output, 512, L"%s: %d", label, value); |
| 93 | + RenderTextLine(output, 0, 255, 0, 1.0f); |
| 94 | + } |
| 95 | + |
| 96 | + void RenderBool(const wchar_t* label, bool value) |
| 97 | + { |
| 98 | + wchar_t output[512]; |
| 99 | + if (value) |
| 100 | + { |
| 101 | + swprintf_s(output, 512, L"%s: %s", label, L"True"); |
| 102 | + } |
| 103 | + else |
| 104 | + { |
| 105 | + swprintf_s(output, 512, L"%s: %s", label, L"False"); |
| 106 | + } |
| 107 | + RenderTextLine(output, 0, 255, 0, 1.0f); |
| 108 | + } |
| 109 | +}; |
| 110 | + |
| 111 | +class AppearanceHUD : public CustomHUD |
| 112 | +{ |
| 113 | +public: |
| 114 | + AppearanceHUD() : CustomHUD("MassEffect") { } |
| 115 | + |
| 116 | + void Update(UCanvas* canvas, ABioPawn* pawn) |
| 117 | + { |
| 118 | + __super::Update(canvas); |
| 119 | + _pawn = pawn; |
| 120 | + } |
| 121 | + |
| 122 | + void Draw() override |
| 123 | + { |
| 124 | + if (!ShouldDraw) return; |
| 125 | + |
| 126 | + SetTextScale(); |
| 127 | + yIndex = 3; |
| 128 | + |
| 129 | + RenderTextLine(L"Appearance Profile", 255, 229, 0, 1.0f); |
| 130 | + if (_pawn) |
| 131 | + { |
| 132 | + RenderName(L"Pawn Name", _pawn->Name); |
| 133 | + auto aType = _pawn->m_oBehavior->m_oActorType; |
| 134 | + if (aType) |
| 135 | + { |
| 136 | + RenderString(L"Actor Game Name", aType->ActorGameName); |
| 137 | + } |
| 138 | + yIndex++; |
| 139 | + RenderMeshSection(); |
| 140 | + if (aType && aType->IsA(UBioPawnChallengeScaledType::StaticClass())) |
| 141 | + { |
| 142 | + yIndex++; |
| 143 | + RenderAppearanceSection(static_cast<UBioPawnChallengeScaledType*>(aType), _pawn->m_oBehavior->m_oAppearanceType); |
| 144 | + } |
| 145 | + } |
| 146 | + else |
| 147 | + { |
| 148 | + RenderTextLine(L"In Mako", 0, 255, 0, 1.0f); |
| 149 | + } |
| 150 | + } |
| 151 | +private: |
| 152 | + ABioPawn* _pawn; |
| 153 | + |
| 154 | + void RenderMeshSection() |
| 155 | + { |
| 156 | + RenderTextLine(L"Meshes:", 255, 229, 0, 1.0f); |
| 157 | + if (_pawn->m_oHairMesh) |
| 158 | + { |
| 159 | + RenderName(L"Hair Mesh", _pawn->m_oHairMesh->SkeletalMesh->Name); |
| 160 | + } |
| 161 | + if (_pawn->m_oHeadMesh) |
| 162 | + { |
| 163 | + RenderName(L"Head Mesh", _pawn->m_oHeadMesh->SkeletalMesh->Name); |
| 164 | + } |
| 165 | + if (_pawn->m_oHeadGearMesh) |
| 166 | + { |
| 167 | + RenderName(L"Head Gear Mesh", _pawn->m_oHeadGearMesh->SkeletalMesh->Name); |
| 168 | + } |
| 169 | + if (_pawn->m_oFacePlateMesh) |
| 170 | + { |
| 171 | + RenderName(L"Face Plate Mesh", _pawn->m_oFacePlateMesh->SkeletalMesh->Name); |
| 172 | + } |
| 173 | + if (_pawn->m_oVisorMesh) |
| 174 | + { |
| 175 | + RenderName(L"Visor Mesh", _pawn->m_oVisorMesh->SkeletalMesh->Name); |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + void RenderAppearanceSection(UBioPawnChallengeScaledType* type, UBioInterface_Appearance* interfaceAppr) |
| 180 | + { |
| 181 | + auto appearance = type->m_oAppearance; |
| 182 | + auto body = appearance->Body; |
| 183 | + auto headGear = body->m_oHeadGearAppearance; |
| 184 | + auto headGearSettings = headGear->m_oSettings; |
| 185 | + |
| 186 | + auto iApprPawn = reinterpret_cast<UBioInterface_Appearance_Pawn*>(interfaceAppr); |
| 187 | + |
| 188 | + RenderTextLine(L"Bio_Appr_Character:", 255, 229, 0, 1.0f); |
| 189 | + RenderName(L"Headgear Prefix:", headGear->m_nmPrefix); |
| 190 | + if (iApprPawn) |
| 191 | + { |
| 192 | + auto armorSpecIdx = iApprPawn->m_oSettings->m_oBodySettings->m_eArmorType; |
| 193 | + RenderInt(L"Armor Spec Index", armorSpecIdx); |
| 194 | + auto armorSpec = headGear->m_aArmorSpec[armorSpecIdx]; |
| 195 | + if (iApprPawn->m_oSettings->m_oBodySettings->m_oHeadGearSettings) |
| 196 | + { |
| 197 | + auto hgrVslOvr = iApprPawn->m_oSettings->m_oBodySettings->m_oHeadGearSettings->m_eVisualOverride; |
| 198 | + RenderInt(L"Headgear Visual Override Armor Spec", hgrVslOvr); |
| 199 | + } |
| 200 | + // Need good way of determining this index |
| 201 | + auto modelSpecIdx = 2; |
| 202 | + if (modelSpecIdx < armorSpec.m_aModelSpec.Count) |
| 203 | + { |
| 204 | + auto modelSpec = armorSpec.m_aModelSpec.Data[modelSpecIdx]; |
| 205 | + RenderInt(L"Hgr ModelSpec Index (currently hardcoded)", modelSpecIdx); |
| 206 | + RenderInt(L"Hgr ModelSpec MaterialConfigCount", modelSpec.m_nMaterialConfigCount); |
| 207 | + RenderBool(L"Hgr ModelSpec bIsHairHidden", modelSpec.m_bIsHairHidden); |
| 208 | + RenderBool(L"Hgr ModelSpec bIsHeadHidden", modelSpec.m_bIsHeadHidden); |
| 209 | + RenderBool(L"Hgr ModelSpec bSuppressFacePlate", modelSpec.m_bSuppressFacePlate); |
| 210 | + RenderBool(L"Hgr ModelSpec bSuppressVisor", modelSpec.m_bSuppressVisor); |
| 211 | + } |
| 212 | + } |
| 213 | + } |
| 214 | +}; |
| 215 | + |
0 commit comments