detect game version
This commit is contained in:
parent
f6fee0982f
commit
da2a639c04
4 changed files with 149 additions and 65 deletions
|
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-std=c++17 -g -Wno-error")
|
||||
set(CMAKE_CXX_FLAGS "-std=c++17 -g -Wno-error -O0")
|
||||
file(GLOB_RECURSE ENDLAUNCHER "src/*.cpp")
|
||||
add_executable(endlauncher ${ENDLAUNCHER})
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@
|
|||
using namespace enginend;
|
||||
|
||||
netio nete{};
|
||||
/*
|
||||
|
||||
*/
|
||||
struct background: public virtual textured {
|
||||
background(Texture2D* texture,float x,float y,float w, float h) {
|
||||
this->pos=Vector2{x,y};this->size=Vector2{w,h};
|
||||
|
|
@ -105,11 +107,14 @@ public:
|
|||
Texture2D playbtn[2];
|
||||
Texture2D menubtn[3];
|
||||
button* buttons[8];
|
||||
button* playbutton;
|
||||
Texture2D buttonslabel[8];
|
||||
Font gamename,changelog,information;
|
||||
bool vsync=true;
|
||||
scene s;
|
||||
RenderTexture2D target;
|
||||
text version;
|
||||
std::string selectedversion="";
|
||||
Image img;
|
||||
bool captured=true;
|
||||
const char* CONF() final{return "test.tdf";}
|
||||
|
|
@ -127,10 +132,13 @@ public:
|
|||
buttonfore=LoadTexture("res/forebuttonon.png");
|
||||
buttonlock=LoadTexture("res/lockbutton.png");
|
||||
gamename=LoadFont("res/showcase.ttf");
|
||||
changelog=LoadFont("res/log.ttf");
|
||||
information=LoadFont("res/info.ttf");
|
||||
menubtn[0]=LoadTexture("res/btn.png");
|
||||
menubtn[1]=LoadTexture("res/btnhover.png");
|
||||
menubtn[2]=LoadTexture("res/btnpress.png");
|
||||
changelog=LoadFont("res/log.ttf");
|
||||
selectedversion=nete.currentversion;
|
||||
version= text (nullptr,Color{255,255,255,255},Color{0,0,0,0},96,16*17,1,1,information,20,"version: "+selectedversion);
|
||||
SetTraceLogLevel(LOG_ERROR);
|
||||
buttons[0]=new button(&menubtn[0], {255,255,255,255},468,58,96,16,nullptr);
|
||||
buttonslabel[0]=LoadTexture("res/options.png");
|
||||
|
|
@ -160,6 +168,7 @@ public:
|
|||
buttonslabel[7]=LoadTexture("res/exit.png");
|
||||
playbtn[0]=LoadTexture("res/playoff.png");
|
||||
playbtn[1]=LoadTexture("res/playon.png");
|
||||
playbutton= new button(&playbtn[0], {255,255,255,255},406,(18*11)+17+9,153,59,nullptr);
|
||||
s.nodes=std::list<node*>{
|
||||
new background(&bg,0,0,600,300),
|
||||
new textured(&buttonfore,3,36,62,62),
|
||||
|
|
@ -175,37 +184,56 @@ public:
|
|||
buttons[5],new textured(&buttonslabel[5],468,58+(18*5),96,16),
|
||||
buttons[6],new textured(&buttonslabel[6],468,58+(18*6)+15,96,16),
|
||||
buttons[7],new textured(&buttonslabel[7],468,58+(18*7)+17,96,16),
|
||||
new button(&playbtn[0], {255,255,255,255},406,(18*11)+17+9,153,59,nullptr),
|
||||
playbutton,
|
||||
new logi(nullptr,Color{255,0,255,255},Color{0,0,0,0},90,58,466,159,changelog,8,nete.changelog),
|
||||
new text(nullptr,Color{255,255,255,255},Color{0,0,0,0},96+16,(16*14)-3,1,1,information,20,"downloaded verified"),
|
||||
&version,
|
||||
};
|
||||
s.boot();
|
||||
}
|
||||
int buttondelay=0;
|
||||
void tick() override {
|
||||
for (button* b : buttons) {
|
||||
if (b->hover) {
|
||||
if (b->pressed) {
|
||||
b->texture=&menubtn[2];
|
||||
buttondelay=5;
|
||||
if (nete.currentversion!=selectedversion) {
|
||||
selectedversion=nete.currentversion;
|
||||
this->version.content="version: "+selectedversion;
|
||||
tiny::echo("selecting version: %s",selectedversion.c_str());
|
||||
}
|
||||
{
|
||||
for (button* b : buttons) {
|
||||
if (b->hover) {
|
||||
if (b->pressed) {
|
||||
b->texture=&menubtn[2];
|
||||
buttondelay=5;
|
||||
}else {
|
||||
if (b->texture->id==menubtn[2].id) {
|
||||
if(buttondelay<0) {
|
||||
b->texture=&menubtn[1];
|
||||
}
|
||||
}else {
|
||||
b->texture=&menubtn[1];
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (b->texture->id==menubtn[2].id) {
|
||||
if(buttondelay<0) {
|
||||
b->texture=&menubtn[1];
|
||||
b->texture=&menubtn[0];
|
||||
}
|
||||
}else {
|
||||
b->texture=&menubtn[1];
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (b->texture->id==menubtn[2].id) {
|
||||
if(buttondelay<0) {
|
||||
b->texture=&menubtn[0];
|
||||
}
|
||||
}else {
|
||||
b->texture=&menubtn[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
if (playbutton->pressed) {
|
||||
playbutton->texture=&playbtn[1];
|
||||
buttondelay=5;
|
||||
}else {
|
||||
if(buttondelay<0) {
|
||||
playbutton->texture=&playbtn[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
s.tick();
|
||||
buttondelay--;
|
||||
}
|
||||
|
|
@ -243,12 +271,29 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
tiny::ErrorLevel tiny::level{6};
|
||||
tiny::ErrorLevel tiny::level{8};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
nete.start();
|
||||
nete.github();
|
||||
tiny::startup((char*)"enginend test",(char*)"1.0");
|
||||
tiny::echo ("checking if cfg.tdf exists, if not create");
|
||||
std::ofstream tdffile("cfg.tdf");
|
||||
tdffile.close();
|
||||
|
||||
tiny::echo ("read cfg.tdf");
|
||||
tiny::TDF_FILE config;config.filepath="cfg.tdf";config.read();
|
||||
std::string version;
|
||||
tiny::echo ("getting version");
|
||||
try {version=config.getstring({"version"});}
|
||||
catch (tiny::TDF_ERR e) {version="NULL";}
|
||||
if (version!="NULL") {
|
||||
nete.currentversion=version;
|
||||
config.setstring({"version"},nete.currentversion);
|
||||
}
|
||||
tiny::echo ("starting net");
|
||||
nete.start();
|
||||
tiny::echo ("downloading github info");
|
||||
nete.github();
|
||||
tiny::echo ("starting launcher");
|
||||
test e;
|
||||
e.boot();
|
||||
|
||||
|
|
@ -257,7 +302,7 @@ int main(int argc, char *argv[]) {
|
|||
std::thread tickthread([&e, &running]() {
|
||||
double tickrate=1.0/e.tickrate;
|
||||
auto lasttick=std::chrono::high_resolution_clock::now();
|
||||
|
||||
|
||||
while (running) {
|
||||
auto now=std::chrono::high_resolution_clock::now();
|
||||
double elapsed=std::chrono::duration_cast<std::chrono::duration<double>>(now-lasttick).count();
|
||||
|
|
@ -290,5 +335,8 @@ int main(int argc, char *argv[]) {
|
|||
tickthread.join();
|
||||
|
||||
e.exit();
|
||||
config.setstring({"version"},nete.currentversion);
|
||||
config.save();
|
||||
config.close();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -29,51 +29,87 @@ struct netio {
|
|||
std::string url="https://github.com/kin-fuyuki/forespend_cpp/releases/download/";
|
||||
std::vector<std::string> *versionhistory;
|
||||
std::string changelog="could not connect to github\nplease check your internet connection";
|
||||
std::string currentversion="NULL";
|
||||
std::string newestversion="";
|
||||
|
||||
void start() {
|
||||
CURL* curltdf = curl_easy_init();
|
||||
CURLcode ret;
|
||||
if (curltdf) {
|
||||
FILE* history = fopen("versions.tdf", "wb");
|
||||
curl_easy_setopt(curltdf, CURLOPT_URL, "https://raw.githubusercontent.com/kin-fuyuki/allgames/refs/heads/master/versions.tdf");
|
||||
curl_easy_setopt(curltdf, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(curltdf, CURLOPT_WRITEDATA, history);
|
||||
ret = curl_easy_perform(curltdf);
|
||||
curl_easy_cleanup(curltdf);
|
||||
fclose(history);
|
||||
|
||||
tiny::TDF_FILE fetchversions;
|
||||
fetchversions.filepath = "versions.tdf";
|
||||
fetchversions.read();
|
||||
boost::unordered_map<std::string,tiny::TDF_DATA>* foreversions= fetchversions.getclass({"forespend"});
|
||||
std::vector<std::string> versions;
|
||||
for (auto version:*foreversions) {
|
||||
tiny::error("path: %s",version.first.c_str());
|
||||
if (version.second.type==tiny::TDF_Type::TDF_DEFINES) {
|
||||
versions=*(std::vector<std::string>*)version.second.datapointer;
|
||||
}
|
||||
}
|
||||
std::sort(versions.begin(), versions.end(), [](const std::string& a, const std::string& b) {
|
||||
int ra = 0, rb = 0;
|
||||
float va = 0.0f, vb = 0.0f;
|
||||
char pa = ' ', pb = ' ';
|
||||
char rea = ' ', reb = ' ';
|
||||
sscanf(a.c_str(), "%d.%f.%c.%c", &ra, &va, &pa, &rea);
|
||||
sscanf(b.c_str(), "%d.%f.%c.%c", &rb, &vb, &pb, &reb);
|
||||
if (ra != rb) return ra > rb;
|
||||
if (va != vb) return va > vb;
|
||||
if (pa != pb) return pa > pb;
|
||||
return rea < reb;
|
||||
});
|
||||
tiny::success("\n\nforespend versions:");
|
||||
for (auto version:versions) {
|
||||
|
||||
tiny::warning("%s",version.c_str());
|
||||
}
|
||||
tiny::success("found\n\n");
|
||||
versionhistory=&versions;
|
||||
}
|
||||
|
||||
}
|
||||
const int MAX_RETRIES = 3;
|
||||
int attempts = 0;
|
||||
bool download_success = false;
|
||||
|
||||
while (attempts < MAX_RETRIES && !download_success) {
|
||||
CURL* curltdf = curl_easy_init();
|
||||
if (curltdf) {
|
||||
FILE* history = fopen("versions.tdf", "wb");
|
||||
if (!history) break;
|
||||
|
||||
curl_easy_setopt(curltdf, CURLOPT_URL, "https://raw.githubusercontent.com/kin-fuyuki/allgames/refs/heads/master/versions.tdf");
|
||||
curl_easy_setopt(curltdf, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(curltdf, CURLOPT_WRITEDATA, history);
|
||||
|
||||
CURLcode ret = curl_easy_perform(curltdf);
|
||||
fclose(history);
|
||||
curl_easy_cleanup(curltdf);
|
||||
|
||||
if (ret == CURLE_OK) {
|
||||
download_success = true;
|
||||
} else {
|
||||
attempts++;
|
||||
tiny::warning("Version fetch failed (Attempt %d/%d): %s", attempts, MAX_RETRIES, curl_easy_strerror(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!download_success) {
|
||||
tiny::fatal("Could not download versions.tdf after %d attempts.", MAX_RETRIES);
|
||||
return;
|
||||
}
|
||||
|
||||
// Processing the file
|
||||
tiny::TDF_FILE fetchversions;
|
||||
fetchversions.filepath = "versions.tdf";
|
||||
fetchversions.read();
|
||||
|
||||
boost::unordered_map<std::string, tiny::TDF_DATA>* foreversions = fetchversions.getclass({"forespend"});
|
||||
if (!foreversions) return;
|
||||
|
||||
std::vector<std::string> versions;
|
||||
for (auto& version : *foreversions) {
|
||||
if (version.second.type == tiny::TDF_Type::TDF_DEFINES) {
|
||||
versions = *(std::vector<std::string>*)version.second.datapointer;
|
||||
}
|
||||
}
|
||||
|
||||
if (versions.empty()) return;
|
||||
|
||||
std::sort(versions.begin(), versions.end(), [](const std::string& a, const std::string& b) {
|
||||
int ra = 0, rb = 0;
|
||||
float va = 0.0f, vb = 0.0f;
|
||||
char pa = ' ', pb = ' ';
|
||||
char rea = ' ', reb = ' ';
|
||||
sscanf(a.c_str(), "%d.%f.%c.%c", &ra, &va, &pa, &rea);
|
||||
sscanf(b.c_str(), "%d.%f.%c.%c", &rb, &vb, &pb, &reb);
|
||||
if (ra != rb) return ra > rb;
|
||||
if (va != vb) return va > vb;
|
||||
if (pa != pb) return pa > pb;
|
||||
return rea < reb;
|
||||
});
|
||||
|
||||
this->newestversion = versions[0]; // Sort is descending, index 0 is newest
|
||||
if (this->newestversion != "") {
|
||||
this->currentversion = newestversion;
|
||||
}
|
||||
|
||||
tiny::success("\n\nforespend versions found:");
|
||||
for (auto& version : versions) {
|
||||
tiny::warning("%s", version.c_str());
|
||||
}
|
||||
|
||||
// Use a member or persistent copy to avoid pointer to local variable
|
||||
static std::vector<std::string> persistent_versions;
|
||||
persistent_versions = versions;
|
||||
versionhistory = &persistent_versions;
|
||||
}
|
||||
void github() {
|
||||
CURL* curl;
|
||||
CURLcode res;
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ inline const char* BOLDWHITE="\033[1m\033[37m";
|
|||
va_end (arg);
|
||||
|
||||
inline void echo(const char * info,...){
|
||||
if (level.value==4)
|
||||
if (level.value>=4)
|
||||
{
|
||||
va_list arg;
|
||||
std::string mixer=info;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue