From c12035a1769c766921d7d3b55fbb78e5533918ab Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Fri, 20 Aug 2021 12:09:59 +0600 Subject: [PATCH] Add timecyc editor (vc) --- src/Ped.cpp | 21 +++++-- src/Ped.h | 1 + src/TimeCycle.h | 150 ++++++++++++++++++++++-------------------------- src/Visual.cpp | 102 +++++++++++++++++++++++--------- src/Visual.h | 8 ++- 5 files changed, 168 insertions(+), 114 deletions(-) diff --git a/src/Ped.cpp b/src/Ped.cpp index 33a193b..3619bc7 100644 --- a/src/Ped.cpp +++ b/src/Ped.cpp @@ -3,6 +3,7 @@ #include "Ui.h" #include "Util.h" #include +#include "Weapon.h" Ped::Ped() { @@ -293,21 +294,29 @@ void Ped::Draw() } } Ui::ListBox("Ped type", m_SpawnPed::m_PedTypeList, m_SpawnPed::m_nSelectedPedType); -#ifdef GTASA - ImGui::Spacing(); - ImGui::Text("Selected weapon: %s", - Weapon::m_WeaponData.m_pJson->m_Data[std::to_string(m_SpawnPed::m_nWeaponId)].get().c_str()); - ImGui::Spacing(); + ImGui::Spacing(); + ImGui::Text("Selected weapon: %s", m_SpawnPed::m_nWeaponName.c_str()); + ImGui::Spacing(); +#ifdef GTASA Ui::DrawImages(Weapon::m_WeaponData, [](std::string str) { m_SpawnPed::m_nWeaponId = std::stoi(str); }, nullptr, [](std::string str) { - return Weapon::m_WeaponData.m_pJson->m_Data[str].get(); + m_SpawnPed::m_nWeaponName = Weapon::m_WeaponData.m_pJson->m_Data[str].get(); + return m_SpawnPed::m_nWeaponName; }, [](std::string str) { return str != "-1"; /*Jetpack*/ } ); +#elif GTAVC + Ui::DrawJSON(Weapon::m_WeaponData, + [](std::string& root, std::string& key, std::string& id) + { + m_SpawnPed::m_nWeaponId = std::stoi(id); + m_SpawnPed::m_nWeaponName = key; + }, + nullptr); #endif ImGui::Spacing(); ImGui::EndChild(); diff --git a/src/Ped.h b/src/Ped.h index 26d5e30..5aaca85 100644 --- a/src/Ped.h +++ b/src/Ped.h @@ -25,6 +25,7 @@ private: inline static bool m_bPedBleed; inline static int m_nSelectedPedType; inline static int m_nWeaponId; + inline static std::string m_nWeaponName = "None"; inline static std::vector m_PedTypeList = { #ifdef GTASA diff --git a/src/TimeCycle.h b/src/TimeCycle.h index 35a2b2d..90a7ed2 100644 --- a/src/TimeCycle.h +++ b/src/TimeCycle.h @@ -1,97 +1,87 @@ -uchar* m_nDirectionalMult = (uchar*)0x55F7C7; //m_nDirectionalMult[184] +uchar* m_nAmbientRed = (uchar*)BY_GAME(0x560C61, 0x9388C8); +uchar* m_nAmbientGreen = (uchar*)BY_GAME(0x55F4D6, 0x78D508); +uchar* m_nAmbientBlue = (uchar*)BY_GAME(0x55F4E8, 0x813D48); -uchar* m_nWaterFogAlpha = (uchar*)0x55F7B8; //m_nWaterFogAlpha[184] +uchar* m_nAmbientRed_Obj = (uchar*)BY_GAME(0x55F4FA, 0x7D53B0); +uchar* m_nAmbientGreen_Obj = (uchar*)BY_GAME(0x55F50C, 0x7D9370); +uchar* m_nAmbientBlue_Obj = (uchar*)BY_GAME(0x55F51E, 0x94C038); -uchar* m_nHighLightMinIntensity = (uchar*)0x55F7A9; //m_nHighLightMinIntensity[184] +uchar* m_nSkyTopRed = (uchar*)BY_GAME(0x55F531, 0x94BE98); +uchar* m_nSkyTopGreen = (uchar*)BY_GAME(0x55F53D, 0x933A58); +uchar* m_nSkyTopBlue = (uchar*)BY_GAME(0x55F549, 0x94A170); -uchar* m_fCloudAlpha = (uchar*)0x55F793; //m_fCloudAlpha[184] +uchar* m_nSkyBottomRed = (uchar*)BY_GAME(0x55F555, 0x7E44A0); +uchar* m_nSkyBottomGreen = (uchar*)BY_GAME(0x55F561, 0x7E9CD0); +uchar* m_nSkyBottomBlue = (uchar*)BY_GAME(0x55F56D, 0x92D420); -uchar* m_fPostFx2Alpha = (uchar*)0x55F77D; //m_fPostFx2Alpha[184] +uchar* m_nSunCoreRed = (uchar*)BY_GAME(0x55F59D, 0x944098); +uchar* m_nSunCoreGreen = (uchar*)BY_GAME(0x55F5A9, 0x7D94C0); +uchar* m_nSunCoreBlue = (uchar*)BY_GAME(0x55F5B5, 0x8614F8); -uchar* m_fPostFx2Blue = (uchar*)0x55F767; //m_fPostFx2Blue[184] +uchar* m_nSunCoronaRed = (uchar*)BY_GAME(0x55F579, 0x78CCD8); +uchar* m_nSunCoronaGreen = (uchar*)BY_GAME(0x55F585, 0x7DBC08); +uchar* m_nSunCoronaBlue = (uchar*)BY_GAME(0x55F591, 0x7D1818); -uchar* m_fPostFx2Green = (uchar*)0x55F751; //m_fPostFx2Green[184] +uchar* m_nLowCloudsRed = (uchar*)BY_GAME(0x55F653, 0x8100C0); +uchar* m_nLowCloudsGreen = (uchar*)BY_GAME(0x55F65F, 0x94AEA0); +uchar* m_nLowCloudsBlue = (uchar*)BY_GAME(0x55F66B, 0x94BDF0); -uchar* m_fPostFx2Red = (uchar*)0x55F73B; //m_fPostFx2Red[184] +uchar* m_fLightsOnGroundBrightness = (uchar*)BY_GAME(0x55F640, 0x92D378); +uchar* m_nPoleShadowStrength = (uchar*)BY_GAME(0x55F60F, 0x812090); +uchar* m_nLightShadowStrength = (uchar*)BY_GAME(0x55F603, 0x811828); +uchar* m_nShadowStrength = (uchar*)BY_GAME(0x55F5F7, 0x92D260); +uchar* m_fSpriteBrightness = (uchar*)BY_GAME(0x55F5E4, 0x7D5308); +uchar* m_fSpriteSize = (uchar*)BY_GAME(0x55F5D2, 0x94B848); +uchar* m_fSunSize = (uchar*)BY_GAME(0x55F5C0, 0x818720); +short* m_fFogStart = (short*)BY_GAME(0x55F62E, 0x94D638); +short* m_fFarClip = (short*)BY_GAME(0x55F61B, 0x94D4E8); -uchar* m_fPostFx1Alpha = (uchar*)0x55F725; //m_fPostFx1Alpha[184] +uchar* m_fWaterRed = (uchar*)BY_GAME(0x55F69C, 0x7E5560); +uchar* m_fWaterGreen = (uchar*)BY_GAME(0x55F6B0, 0x7DE148); +uchar* m_fWaterBlue = (uchar*)BY_GAME(0x55F6C3, 0x862248); +uchar* m_fWaterAlpha = (uchar*)BY_GAME(0x55F6D6, 0x7DDAE0); -uchar* m_fPostFx1Blue = (uchar*)0x55F70F; //m_fPostFx1Blue[184] +#ifdef GTASA +uchar* m_fPostFx2Alpha = (uchar*)0x55F77D; +uchar* m_fPostFx2Blue = (uchar*)0x55F767; +uchar* m_fPostFx2Green = (uchar*)0x55F751; +uchar* m_fPostFx2Red = (uchar*)0x55F73B; +uchar* m_fPostFx1Alpha = (uchar*)0x55F725; +uchar* m_fPostFx1Blue = (uchar*)0x55F70F; +uchar* m_fPostFx1Green = (uchar*)0x55F6FC; +uchar* m_fPostFx1Red = (uchar*)0x55F6E9; -uchar* m_fPostFx1Green = (uchar*)0x55F6FC; //m_fPostFx1Green[184] +uchar* m_nFluffyCloudsBottomRed = (uchar*)0x55F677; +uchar* m_nFluffyCloudsBottomGreen = (uchar*)0x55F683; +uchar* m_nFluffyCloudsBottomBlue = (uchar*)0x55F690; -uchar* m_fPostFx1Red = (uchar*)0x55F6E9; //m_fPostFx1Red[184] +uchar* m_nDirectionalMult = (uchar*)0x55F7C7; +uchar* m_nWaterFogAlpha = (uchar*)0x55F7B8; +uchar* m_nHighLightMinIntensity = (uchar*)0x55F7A9; +uchar* m_fCloudAlpha = (uchar*)0x55F793; -uchar* m_fWaterAlpha = (uchar*)0x55F6D6; //m_fWaterAlpha[184] +#elif GTAVC +uchar* m_nAmbientBlRed = (uchar*)0x78D5B0; +uchar* m_nAmbientBlGreen = (uchar*)0x861430; +uchar* m_nAmbientBlBlue = (uchar*)0x811740; -uchar* m_fWaterBlue = (uchar*)0x55F6C3; //m_fWaterBlue[184] +uchar* m_nAmbientBlRed_Obj = (uchar*)0x7D9418; +uchar* m_nAmbientBlGreen_Obj = (uchar*)0x818FC0; +uchar* m_nAmbientBlBlue_Obj = (uchar*)0x813B68; -uchar* m_fWaterGreen = (uchar*)0x55F6B0; //m_fWaterGreen[184] +uchar* m_nDirRed = (uchar*)0x7E45E0; +uchar* m_nDirGreen = (uchar*)0x7DDDF8; +uchar* m_nDirBlue = (uchar*)0x92D1B8; -uchar* m_fWaterRed = (uchar*)0x55F69C; //m_fWaterRed[184] +uchar* m_nTopCloudsRed = (uchar*)0x7F3C80; +uchar* m_nTopCloudsGreen = (uchar*)0x813F70; +uchar* m_nTopCloudsBlue = (uchar*)0x938980; -uchar* m_nFluffyCloudsBottomBlue = (uchar*)0x55F690; //m_nFluffyCloudsBottomBlue[184] +uchar* m_nBottomCloudsRed = (uchar*)0x7D3D98; +uchar* m_nBottomCloudsGreen = (uchar*)0x7FFE38; +uchar* m_nBottomCloudsBlue = (uchar*)0x7D9630; -uchar* m_nFluffyCloudsBottomGreen = (uchar*)0x55F683; //m_nFluffyCloudsBottomGreen[184] - -uchar* m_nFluffyCloudsBottomRed = (uchar*)0x55F677; //m_nFluffyCloudsBottomRed[184] - -uchar* m_nLowCloudsBlue = (uchar*)0x55F66B; //m_nLowCloudsBlue[184] - -uchar* m_nLowCloudsGreen = (uchar*)0x55F65F; //m_nLowCloudsGreen[184] - -uchar* m_nLowCloudsRed = (uchar*)0x55F653; //m_nLowCloudsRed[184] - -uchar* m_fLightsOnGroundBrightness = (uchar*)0x55F640; //m_fLightsOnGroundBrightness[184] - -short* m_fFogStart = (short*)0x55F62E; //m_fFogStart[184] - -short* m_fFarClip = (short*)0x55F61B; //m_fFarClip[184] - -uchar* m_nPoleShadowStrength = (uchar*)0x55F60F; //m_nPoleShadowStrength[184] - -uchar* m_nLightShadowStrength = (uchar*)0x55F603; //m_nLightShadowStrength[184] - -uchar* m_nShadowStrength = (uchar*)0x55F5F7; //m_nShadowStrength[184] - -uchar* m_fSpriteBrightness = (uchar*)0x55F5E4; //m_fSpriteBrightness[184] - -uchar* m_fSpriteSize = (uchar*)0x55F5D2; //m_fSpriteSize[184] - -uchar* m_fSunSize = (uchar*)0x55F5C0; //m_fSunSize[184] - -uchar* m_nSunCoronaBlue = (uchar*)0x55F5B5; //m_nSunCoronaBlue[184] - -uchar* m_nSunCoronaGreen = (uchar*)0x55F5A9; //m_nSunCoronaGreen[184] - -uchar* m_nSunCoronaRed = (uchar*)0x55F59D; //m_nSunCoronaRed[184] - -uchar* m_nSunCoreBlue = (uchar*)0x55F591; //m_nSunCoreBlue[184] - -uchar* m_nSunCoreGreen = (uchar*)0x55F585; //m_nSunCoreGreen[184] - -uchar* m_nSunCoreRed = (uchar*)0x55F579; //m_nSunCoreRed[184] - -uchar* m_nSkyBottomBlue = (uchar*)0x55F56D; //m_nSkyBottomBlue[184] - -uchar* m_nSkyBottomGreen = (uchar*)0x55F561; //m_nSkyBottomGreen[184] - -uchar* m_nSkyBottomRed = (uchar*)0x55F555; //m_nSkyBottomRed[184] - -uchar* m_nSkyTopBlue = (uchar*)0x55F549; //m_nSkyTopBlue[45] - -uchar* m_nSkyTopGreen = (uchar*)0x55F53D; //m_nSkyTopGreen[45] - -uchar* m_nSkyTopRed = (uchar*)0x55F531; //m_nSkyTopRed[45] - -uchar* m_nAmbientBlue_Obj = (uchar*)0x55F51E; //m_nAmbientBlue_Obj[184] - -uchar* m_nAmbientGreen_Obj = (uchar*)0x55F50C; //m_nAmbientGreen_Obj[184] - -uchar* m_nAmbientRed_Obj = (uchar*)0x55F4FA; //m_nAmbientRed_Obj[184] - -uchar* m_nAmbientBlue = (uchar*)0x55F4E8; //m_nAmbientBlue[184] - -uchar* m_nAmbientGreen = (uchar*)0x55F4D6; //m_nAmbientGreen[184] - -uchar* m_nAmbientRed = (uchar*)0x560C61; //m_nAmbientRed[184] +uchar* m_nBlurRed = (uchar*)0x94B790; +uchar* m_nBlurGreen = (uchar*)0x8621A0; +uchar* m_nBlurBlue = (uchar*)0x945728; +#endif diff --git a/src/Visual.cpp b/src/Visual.cpp index da31a4c..9ad8474 100644 --- a/src/Visual.cpp +++ b/src/Visual.cpp @@ -29,40 +29,49 @@ Visual::Visual() }; } -// Thanks to GuruGuru -int Visual::GetCurrentHourTimeId(int hour) +int Visual::CalcArrayIndex() { - if (hour == -1) + int hour = CClock::ms_nGameClockHours; + +#ifdef GTASA + int result = 0; + + if (m_nTimecycHour == 24) { - hour = CClock::ms_nGameClockHours; + result = hour; + } + else + { + if (hour < 5) result = 0; + if (hour == 5) result = 1; + if (hour == 6) result = 2; + if (7 <= hour && hour < 12) result = 3; + if (12 <= hour && hour < 19) result = 4; + if (hour == 19) result = 5; + if (hour == 20 || hour == 21) result = 6; + if (hour == 22 || hour == 23) result = 7; } - if (m_nTimecycHour == 24) - return hour; - - if (hour < 5) return 0; - if (hour == 5) return 1; - - if (hour == 6) return 2; - - if (7 <= hour && hour < 12) return 3; - if (12 <= hour && hour < 19) return 4; - - if (hour == 19) return 5; - if (hour == 20 || hour == 21) return 6; - if (hour == 22 || hour == 23) return 7; - - return NULL; + return 23 * result + CWeather::OldWeatherType; +#elif GTAVC + return 7 * hour + CWeather::OldWeatherType; +#endif } bool Visual::TimeCycColorEdit3(const char* label, uchar* r, uchar* g, uchar* b, ImGuiColorEditFlags flags) { bool rtn = false; - int val = 23 * GetCurrentHourTimeId() + CWeather::OldWeatherType; + int val = CalcArrayIndex(); +#ifdef GTASA auto red = static_cast(patch::GetPointer(int(r))); auto green = static_cast(patch::GetPointer(int(g))); auto blue = static_cast(patch::GetPointer(int(b))); +#elif GTAVC + auto red = static_cast(r); + auto green = static_cast(g); + auto blue = static_cast(b); +#endif float col[3]{ red[val] / 255.0f, green[val] / 255.0f, blue[val] / 255.0f }; @@ -80,12 +89,19 @@ bool Visual::TimeCycColorEdit3(const char* label, uchar* r, uchar* g, uchar* b, bool Visual::TimeCycColorEdit4(const char* label, uchar* r, uchar* g, uchar* b, uchar* a, ImGuiColorEditFlags flags) { bool rtn = false; - int val = 23 * GetCurrentHourTimeId() + CWeather::OldWeatherType; + int val = CalcArrayIndex(); +#ifdef GTASA auto red = static_cast(patch::GetPointer(int(r))); auto green = static_cast(patch::GetPointer(int(g))); auto blue = static_cast(patch::GetPointer(int(b))); auto alpha = static_cast(patch::GetPointer(int(a))); +#elif GTAVC + auto red = static_cast(r); + auto green = static_cast(g); + auto blue = static_cast(b); + auto alpha = static_cast(a); +#endif float col[4]{ red[val] / 255.0f, green[val] / 255.0f, blue[val] / 255.0f, alpha[val] / 255.0f }; @@ -104,17 +120,26 @@ bool Visual::TimeCycColorEdit4(const char* label, uchar* r, uchar* g, uchar* b, template int GetTCVal(T* addr, int index) { +#ifdef GTASA T* arr = static_cast(patch::GetPointer(int(addr))); +#elif GTAVC + T* arr = static_cast(addr); +#endif return static_cast(arr[index]); } void Visual::GenerateTimecycFile() { +#ifdef GTASA std::ofstream file; if (m_nTimecycHour == 24) + { file = std::ofstream("timecyc_24h.dat"); + } else + { file = std::ofstream("timecyc.dat"); + } for (uint i = 0; i < m_WeatherNames.size(); ++i) { @@ -194,6 +219,7 @@ void Visual::GenerateTimecycFile() std::endl; } } +#endif } void Visual::Draw() @@ -381,6 +407,9 @@ void Visual::Draw() #ifdef GTASA if (m_nTimecycHour == 8 ? ImGui::BeginTabItem("Timecyc") : ImGui::BeginTabItem("Timecyc 24h")) +#elif GTAVC + if (ImGui::BeginTabItem("Timecyc")) +#endif { ImGui::Spacing(); if (ImGui::Button("Generate timecyc file", Ui::GetSize(2))) @@ -398,11 +427,15 @@ void Visual::Draw() int weather = CWeather::OldWeatherType; if (Ui::ListBox("Current weather", m_WeatherNames, weather)) + { CWeather::OldWeatherType = weather; + } weather = CWeather::NewWeatherType; if (Ui::ListBox("Next weather", m_WeatherNames, weather)) + { CWeather::NewWeatherType = weather; + } ImGui::Spacing(); int hour = CClock::ms_nGameClockHours; @@ -439,11 +472,11 @@ void Visual::Draw() { if (Game::m_bFreezeTime) { - patch::SetRaw(0x52CF10, (char*)"\xEB\xEF", 2); + patch::SetRaw(BY_GAME(0x52CF10, 0x487010), (char*)"\xEB\xEF", 2); } else { - patch::SetRaw(0x52CF10, (char*)"\x56\x8B", 2); + patch::SetRaw(BY_GAME(0x52CF10, 0x487010), (char*)BY_GAME("\x56\x8B","\x6A\x01"), 2); } } ImGui::Spacing(); @@ -456,12 +489,24 @@ void Visual::Draw() TimeCycColorEdit3("Ambient", m_nAmbientRed, m_nAmbientGreen, m_nAmbientBlue); TimeCycColorEdit3("Ambient obj", m_nAmbientRed_Obj, m_nAmbientGreen_Obj, m_nAmbientBlue_Obj); + +#ifdef GTASA TimeCycColorEdit3("Fluffy clouds", m_nFluffyCloudsBottomRed, m_nFluffyCloudsBottomGreen, m_nFluffyCloudsBottomBlue); +#elif GTAVC + TimeCycColorEdit3("Ambient bl", m_nAmbientBlRed, m_nAmbientBlGreen, m_nAmbientBlBlue); + TimeCycColorEdit3("Ambient obj bl", m_nAmbientBlRed_Obj, m_nAmbientBlGreen_Obj, m_nAmbientBlBlue_Obj); + TimeCycColorEdit3("Blur", m_nBlurRed, m_nBlurGreen, m_nBlurBlue); + TimeCycColorEdit3("Clouds bottom", m_nBottomCloudsRed, m_nBottomCloudsGreen, m_nBottomCloudsBlue); + TimeCycColorEdit3("Clouds top", m_nTopCloudsRed, m_nTopCloudsGreen, m_nTopCloudsBlue); + TimeCycColorEdit3("Directional light", m_nDirRed, m_nDirGreen, m_nDirBlue); +#endif TimeCycColorEdit3("Low clouds", m_nLowCloudsRed, m_nLowCloudsGreen, m_nLowCloudsBlue); +#ifdef GTASA TimeCycColorEdit4("Postfx 1", m_fPostFx1Red, m_fPostFx1Green, m_fPostFx1Blue, m_fPostFx1Alpha); TimeCycColorEdit4("Postfx 2", m_fPostFx2Red, m_fPostFx2Green, m_fPostFx2Blue, m_fPostFx1Alpha); +#endif TimeCycColorEdit3("Sky bottom", m_nSkyBottomRed, m_nSkyBottomGreen, m_nSkyBottomBlue); TimeCycColorEdit3("Sun core", m_nSunCoreRed, m_nSunCoreGreen, m_nSunCoreBlue); @@ -477,11 +522,16 @@ void Visual::Draw() { ImGui::BeginChild("TimecycMisc"); ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth() / 2); + +#ifdef GTASA TimecycSlider("Cloud alpha", m_fCloudAlpha, 0, 255); TimecycSlider("Directional mult", m_nDirectionalMult, 0, 255); +#endif TimecycSlider("Far clip", m_fFarClip, 0, 2000); TimecycSlider("Fog start", m_fFogStart, 0, 1500); +#ifdef GTASA TimecycSlider("High light min intensity", m_nHighLightMinIntensity, 0, 255); +#endif TimecycSlider("Light on ground brightness", m_fLightsOnGroundBrightness, 0, 255); TimecycSlider("Light shadow strength", m_nLightShadowStrength, 0, 255); TimecycSlider("Pole shadow strength", m_nPoleShadowStrength, 0, 255); @@ -489,7 +539,9 @@ void Visual::Draw() TimecycSlider("Sprite brightness", m_fSpriteBrightness, 0, 127); TimecycSlider("Sprite size", m_fSpriteSize, 0, 127); TimecycSlider("Sun size", m_fSunSize, 0, 127); +#ifdef GTASA TimecycSlider("Water fog alpha", m_nWaterFogAlpha, 0, 255); +#endif ImGui::PopItemWidth(); ImGui::Spacing(); @@ -498,10 +550,8 @@ void Visual::Draw() } ImGui::EndTabBar(); } - ImGui::EndTabItem(); } -#endif ImGui::EndTabBar(); } } diff --git a/src/Visual.h b/src/Visual.h index 0434e96..0da31b4 100644 --- a/src/Visual.h +++ b/src/Visual.h @@ -18,7 +18,7 @@ private: }; static void GenerateTimecycFile(); - static int GetCurrentHourTimeId(int hour = -1); + static int CalcArrayIndex(); static bool TimeCycColorEdit3(const char* label, uchar* r, uchar* g, uchar* b, ImGuiColorEditFlags flags = 0); static bool TimeCycColorEdit4(const char* label, uchar* r, uchar* g, uchar* b, uchar* a, ImGuiColorEditFlags flags = 0); @@ -32,8 +32,12 @@ public: template void Visual::TimecycSlider(const char* label, T* ptr, int min, int max) { - int val = 23 * GetCurrentHourTimeId() + CWeather::OldWeatherType; + int val = CalcArrayIndex(); +#ifdef GTASA T* arr = static_cast(patch::GetPointer(int(ptr))); +#elif GTAVC + T* arr = static_cast(ptr); +#endif int a = arr[val]; if (ImGui::SliderInt(label, &a, min, max))