Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Therjak/menu #12

Merged
merged 2 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions maptimer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<GW2MapTimer>
<Categories>
<Category Color="C08AEAF4" Name="Core Tyria" id="core" />
<Category Color="C079afff" Name="Special Events" id="special" />
<Category Color="C0FBE384" Name="Living World Season 2" id="lws2" />
<Category Color="C0BED742" Name="Hearth of Thorns" id="hot" />
<Category Color="C0D7425B" Name="Living World Season 3" id="lws3" />
Expand All @@ -11,6 +12,7 @@
<Category Color="C06984E4" Name="Eye of the North" id="eotn" />
<Category Color="C079afff" Name="End of Dragons" id="eod" />
<Category Color="C0facd85" Name="Secrets of the Obscure" id="soto" />
<Category Color="C0c4ffd4" Name="Janthir Wilds" id="jw" />
</Categories>
<Maps>
<Map Name="Daytime" Length="120" Start="25" id="daytime">
Expand All @@ -19,6 +21,20 @@
<Event Name="Dusk" Length="5" Color="80ffe37f" />
<Event Name="Night" Length="40" Color="809f99cc" />
</Map>
<Map Category="special" Name="Labyrinthine Cliffs" Length="120" Start="0" id="se">
<Event Name="Skiff Race" Length="10" Color="8042c8d7" />
<Event Name="" Length="5" Color="00000000" />
<Event Name="Water Ballons" Length="10" Color="8042c8d7" />
<Event Name="" Length="5" Color="00000000" />
<Event Name="Treasure Hunt" Length="30" Color="8042c8d7" />
<Event Name="" Length="15" Color="00000000" />
<Event Name="Skimmer Race" Length="10" Color="8042c8d7" />
<Event Name="" Length="5" Color="00000000" />
<Event Name="Fishing" Length="10" Color="8042c8d7" />
<Event Name="" Length="5" Color="00000000" />
<Event Name="Dolyak Race" Length="10" Color="8042c8d7" />
<Event Name="" Length="5" Color="00000000" />
</Map>
<Map Category="core" Name="World Bosses" Length="1440" Start="0" id="wb">
<Event Name="Taidha" Length="15" Color="8063471c" WorldBossAPIID="admiral_taidha_covington" />
<Event Name="Shaman" Length="15" Color="80b9d0d5" WorldBossAPIID="svanir_shaman_chief" />
Expand Down Expand Up @@ -312,5 +328,9 @@
<Event Name="Convergences" Length="10" Color="80d29b49" />
<Event Name="" Length="170" Color="00000000" />
</Map>
<Map Category="jw" Name="Janthir Syntri" Length="120" Start="30" id="jwjs">
<Event Name="" Length="30" Color="8092aaeb" />
<Event Name="" Length="90" Color="00000000" />
</Map>
</Maps>
</GW2MapTimer>
91 changes: 0 additions & 91 deletions src/gw2_pois.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,87 +580,6 @@ bool DownloadFile(std::string_view url, CStreamWriterMemory& mem) {
return true;
}

std::mutex loadListMutex;
std::vector<std::string> loadList;

void FetchMarkerPackOnline(std::string_view ourl) {
int32_t pos = ourl.find("gw2taco://markerpack/");
if (pos == ourl.npos) {
Log_Err("[GW2TacO] Trying to access malformed package url {:s}", ourl);
return;
}

Log_Nfo("[GW2TacO] Trying to fetch marker pack {:s}", ourl.substr(pos));

std::string url(ourl.substr(pos + 21));
std::thread downloadThread(
[](std::string url) {
CStreamWriterMemory mem;
if (!DownloadFile(url, mem)) {
Log_Err("[GW2TacO] Failed to download package {:s}", url);
return;
}

mz_zip_archive zip;
memset(&zip, 0, sizeof(zip));
if (!mz_zip_reader_init_mem(&zip, mem.GetData(), mem.GetLength(), 0)) {
Log_Err(
"[GW2TacO] Package {:s} doesn't seem to be a well formed zip "
"file",
url);
return;
}

mz_zip_reader_end(&zip);

int32_t cnt = 0;
for (uint32_t x = 0; x < url.size(); x++) {
if (url[x] == '\\' || url[x] == '/') {
cnt = x;
}
}

auto fileName = url.substr(size_t(cnt) + 1);
if (fileName.empty()) {
Log_Err("[GW2TacO] Package {:s} has a malformed name", url);
return;
}

if (fileName.find(".zip") == fileName.size() - 4) {
fileName = fileName.substr(0, fileName.size() - 4);
}

if (fileName.find(".taco") == fileName.size() - 5) {
fileName = fileName.substr(0, fileName.size() - 5);
}

for (char& x : fileName) {
if (!isalnum(x)) {
x = '_';
}
}

fileName = "POIs/" + fileName + ".taco";

CStreamWriterFile out;
if (!out.Open(fileName)) {
Log_Err("[GW2TacO] Failed to open file for writing: {:s}", fileName);
return;
}

if (!out.Write(uint8_view(mem.GetData(), mem.GetLength()))) {
Log_Err("[GW2TacO] Failed to write out data to file: {:s}", fileName);
remove(fileName.c_str());
return;
}
std::scoped_lock l(loadListMutex);
loadList.emplace_back(std::move(fileName));
},
url);
// TODO(therjak): this needs a fix
downloadThread.detach();
}

void ImportMarkerPack(CWBApplication* App, std::string_view zipFile);

void FlushZipDict();
Expand Down Expand Up @@ -741,8 +660,6 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
Log_Nfo("[GW2TacO] WM_COPYDATA sent. Result code: {:d}", GetLastError());
return 0;
}

FetchMarkerPackOnline(cmdLine);
}

if (cmdLine.find("-forcenewinstance") == cmdLine.npos) {
Expand Down Expand Up @@ -927,14 +844,6 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
}
}
}
{
std::scoped_lock l(loadListMutex);
if (!loadList.empty()) {
auto file = loadList[0];
loadList.erase(loadList.begin());
ImportMarkerPack(App.get(), file);
}
}

for (int x = 0; x < (frameThrottling ? 32 : 1); x++) {
if (mumbleLink.Update()) {
Expand Down
15 changes: 7 additions & 8 deletions src/gw2_taco.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "src/gw2_taco.h"

#include <shellapi.h>
#include <shellapi.h> // TODO: open web page

#include <algorithm>
#include <format>
Expand Down Expand Up @@ -1065,11 +1065,11 @@ bool GW2TacO::MessageProc(const CWBMessage& Message) {
// App->ReApplyStyle();
// return true;
// break;
case Menu_DownloadNewBuild:
ShellExecute(App->GetHandle(), "open", "http://www.gw2taco.com",
nullptr, nullptr, SW_SHOW);
return true;
break;
// case Menu_DownloadNewBuild:
// ShellExecute(App->GetHandle(), "open", "http://www.gw2taco.com",
// nullptr, nullptr, SW_SHOW);
// return true;
// break;
case Menu_ToggleRangeCircles:
ToggleConfigValue("RangeCirclesVisible");
return true;
Expand Down Expand Up @@ -1514,8 +1514,7 @@ void GW2TacO::OpenAboutWindow() {
"(c) BoyC / Conspiracy");
l1->ApplyStyleDeclarations(
"font-family:ProFont;text-align:center;vertical-align:top;");
l1 = CWBLabel::Create(w, w->GetClientRect() + CPoint(0, 48),
"(c) therjak");
l1 = CWBLabel::Create(w, w->GetClientRect() + CPoint(0, 48), "(c) therjak");
l1->ApplyStyleDeclarations(
"font-family:ProFont;text-align:center;vertical-align:top;");
l1 = CWBLabel::Create(w, w->GetClientRect() + CPoint(0, 64),
Expand Down
12 changes: 7 additions & 5 deletions src/gw2_tactical.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "src/gw2_tactical.h"

#include <math.h>
#include <mmsystem.h>

#include <algorithm>
#include <chrono>
#include <cmath>
#include <format>
#include <iterator>
Expand Down Expand Up @@ -71,9 +69,13 @@ std::string_view AddStringToSet(std::string_view string) {
return *p.first;
}

int32_t tacoStartTime = timeGetTime();
auto tacoStartTime = std::chrono::system_clock::now();

int32_t GetTime() { return timeGetTime() - tacoStartTime; }
int32_t GetTime() {
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - tacoStartTime);
return static_cast<int32_t>(milliseconds.count());
}

void UpdateWvWStatus();

Expand Down
5 changes: 2 additions & 3 deletions src/mumble_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using math::CVector2;
using math::CVector3;
using math::CVector4;

CMumbleLink mumbleLink;
CMumbleLink mumbleLink("MumbleLink");
bool frameTriggered = false;
extern std::unique_ptr<CWBApplication> App;

Expand Down Expand Up @@ -83,7 +83,6 @@ bool CMumbleLink::Update() {
}

if (tick == lm->uiTick) {
// memcpy(&lastData, lm, sizeof(LinkedMem));
return false;
} else {
memcpy(&prevData, &lastData, sizeof(LinkedMem));
Expand Down Expand Up @@ -299,7 +298,7 @@ float CMumbleLink::GetFrameRate() {
return 1000.0f / (FrameTimeAcc / static_cast<float>(FrameCount));
}

CMumbleLink::CMumbleLink() {
CMumbleLink::CMumbleLink(std::string_view mumblePath) : mumblePath(mumblePath) {
LastFrameTime = GetTime();
FrameTimes = std::make_unique<CRingBuffer<int32_t, 60>>();
}
Expand Down
4 changes: 2 additions & 2 deletions src/mumble_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct LinkedMem {

class CMumbleLink {
public:
CMumbleLink();
CMumbleLink(std::string_view mumblePath);
virtual ~CMumbleLink();

bool Update();
Expand Down Expand Up @@ -115,7 +115,7 @@ class CMumbleLink {
bool camDirChanged = false;
bool camUpChanged = false;

std::string mumblePath = "MumbleLink";
std::string mumblePath;
uint32_t lastGW2ProcessID = 0;

private:
Expand Down
21 changes: 0 additions & 21 deletions src/overlay_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,3 @@ bool COverlayApp::DeviceOK() {
if (!Device) return false;
return Device->DeviceOk();
}

void FetchMarkerPackOnline(std::string_view ourl);

LRESULT COverlayApp::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_COPYDATA:
auto pcpy = (PCOPYDATASTRUCT)lParam;
if (pcpy) {
std::string_view incoming(static_cast<char*>(pcpy->lpData),
pcpy->cbData);
FetchMarkerPackOnline(incoming);
}
break;
}

if (uMsg > 0x60ff) {
int z = 0;
}

return CWBApplication::WindowProc(uMsg, wParam, lParam);
}
1 change: 0 additions & 1 deletion src/overlay_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ class COverlayApp : public CWBApplication {
std::unique_ptr<CCoreBlendState> holePunchBlendState;

protected:
LRESULT WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
bool DeviceOK() override;
};
44 changes: 16 additions & 28 deletions src/util/xml_document.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#include "xml_document.h"

#include <windows.h>
//
#include <combaseapi.h>
#include <fileapi.h>
#include <objbase.h>

#include <cstdio>
#include <sstream>
#include <string>
Expand All @@ -18,28 +12,24 @@

namespace {
std::string ReadFile(std::string_view name) {
HANDLE hFile =
CreateFile(name.data(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_EXISTING, 0, nullptr);
if (hFile == INVALID_HANDLE_VALUE) {
return {};
}
int32_t size = GetFileSize(hFile, nullptr);
auto ret = std::string(size, 0);
DWORD nRead = 0;
bool b = ::ReadFile(hFile, ret.data(), size, &nRead, nullptr);
CloseHandle(hFile);
if (!b || nRead != size) {
std::FILE* fp = std::fopen(name.data(), "rb");
if (!fp) {
return {};
}
return ret;
std::string contents;
std::fseek(fp, 0, SEEK_END);
contents.resize(std::ftell(fp));
std::rewind(fp);
std::fread(contents.data(), 1, contents.size(), fp);
std::fclose(fp);
return (contents);
}
} // namespace

CXMLDocument::CXMLDocument()
: doc(std::make_unique<rapidxml::xml_document<>>()) {}

CXMLDocument::~CXMLDocument() { CoUninitialize(); }
CXMLDocument::~CXMLDocument() {}

bool CXMLDocument::LoadFromFile(std::string_view szFileName) {
memString = ReadFile(szFileName);
Expand Down Expand Up @@ -80,13 +70,11 @@ std::string CXMLDocument::SaveToString() {

bool CXMLDocument::SaveToFile(std::string_view sz) {
auto s = SaveToString();

HANDLE h = CreateFile(sz.data(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0,
nullptr);
if (h == INVALID_HANDLE_VALUE) return false;
DWORD b = 0;
WriteFile(h, s.c_str(), s.length(), &b, nullptr);
CloseHandle(h);

std::FILE* fp = std::fopen(sz.data(), "wb");
if (!fp) {
return false;
}
std::fwrite(s.c_str(), 1, s.size(), fp);
std::fclose(fp);
return true;
}
2 changes: 0 additions & 2 deletions src/white_board/TODO.txt

This file was deleted.

Loading