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)
|
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")
|
file(GLOB_RECURSE ENDLAUNCHER "src/*.cpp")
|
||||||
add_executable(endlauncher ${ENDLAUNCHER})
|
add_executable(endlauncher ${ENDLAUNCHER})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,9 @@
|
||||||
using namespace enginend;
|
using namespace enginend;
|
||||||
|
|
||||||
netio nete{};
|
netio nete{};
|
||||||
|
/*
|
||||||
|
|
||||||
|
*/
|
||||||
struct background: public virtual textured {
|
struct background: public virtual textured {
|
||||||
background(Texture2D* texture,float x,float y,float w, float h) {
|
background(Texture2D* texture,float x,float y,float w, float h) {
|
||||||
this->pos=Vector2{x,y};this->size=Vector2{w,h};
|
this->pos=Vector2{x,y};this->size=Vector2{w,h};
|
||||||
|
|
@ -105,11 +107,14 @@ public:
|
||||||
Texture2D playbtn[2];
|
Texture2D playbtn[2];
|
||||||
Texture2D menubtn[3];
|
Texture2D menubtn[3];
|
||||||
button* buttons[8];
|
button* buttons[8];
|
||||||
|
button* playbutton;
|
||||||
Texture2D buttonslabel[8];
|
Texture2D buttonslabel[8];
|
||||||
Font gamename,changelog,information;
|
Font gamename,changelog,information;
|
||||||
bool vsync=true;
|
bool vsync=true;
|
||||||
scene s;
|
scene s;
|
||||||
RenderTexture2D target;
|
RenderTexture2D target;
|
||||||
|
text version;
|
||||||
|
std::string selectedversion="";
|
||||||
Image img;
|
Image img;
|
||||||
bool captured=true;
|
bool captured=true;
|
||||||
const char* CONF() final{return "test.tdf";}
|
const char* CONF() final{return "test.tdf";}
|
||||||
|
|
@ -127,10 +132,13 @@ public:
|
||||||
buttonfore=LoadTexture("res/forebuttonon.png");
|
buttonfore=LoadTexture("res/forebuttonon.png");
|
||||||
buttonlock=LoadTexture("res/lockbutton.png");
|
buttonlock=LoadTexture("res/lockbutton.png");
|
||||||
gamename=LoadFont("res/showcase.ttf");
|
gamename=LoadFont("res/showcase.ttf");
|
||||||
|
changelog=LoadFont("res/log.ttf");
|
||||||
|
information=LoadFont("res/info.ttf");
|
||||||
menubtn[0]=LoadTexture("res/btn.png");
|
menubtn[0]=LoadTexture("res/btn.png");
|
||||||
menubtn[1]=LoadTexture("res/btnhover.png");
|
menubtn[1]=LoadTexture("res/btnhover.png");
|
||||||
menubtn[2]=LoadTexture("res/btnpress.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);
|
SetTraceLogLevel(LOG_ERROR);
|
||||||
buttons[0]=new button(&menubtn[0], {255,255,255,255},468,58,96,16,nullptr);
|
buttons[0]=new button(&menubtn[0], {255,255,255,255},468,58,96,16,nullptr);
|
||||||
buttonslabel[0]=LoadTexture("res/options.png");
|
buttonslabel[0]=LoadTexture("res/options.png");
|
||||||
|
|
@ -160,6 +168,7 @@ public:
|
||||||
buttonslabel[7]=LoadTexture("res/exit.png");
|
buttonslabel[7]=LoadTexture("res/exit.png");
|
||||||
playbtn[0]=LoadTexture("res/playoff.png");
|
playbtn[0]=LoadTexture("res/playoff.png");
|
||||||
playbtn[1]=LoadTexture("res/playon.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*>{
|
s.nodes=std::list<node*>{
|
||||||
new background(&bg,0,0,600,300),
|
new background(&bg,0,0,600,300),
|
||||||
new textured(&buttonfore,3,36,62,62),
|
new textured(&buttonfore,3,36,62,62),
|
||||||
|
|
@ -175,13 +184,21 @@ public:
|
||||||
buttons[5],new textured(&buttonslabel[5],468,58+(18*5),96,16),
|
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[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),
|
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 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();
|
s.boot();
|
||||||
}
|
}
|
||||||
int buttondelay=0;
|
int buttondelay=0;
|
||||||
void tick() override {
|
void tick() override {
|
||||||
|
if (nete.currentversion!=selectedversion) {
|
||||||
|
selectedversion=nete.currentversion;
|
||||||
|
this->version.content="version: "+selectedversion;
|
||||||
|
tiny::echo("selecting version: %s",selectedversion.c_str());
|
||||||
|
}
|
||||||
|
{
|
||||||
for (button* b : buttons) {
|
for (button* b : buttons) {
|
||||||
if (b->hover) {
|
if (b->hover) {
|
||||||
if (b->pressed) {
|
if (b->pressed) {
|
||||||
|
|
@ -206,6 +223,17 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if (playbutton->pressed) {
|
||||||
|
playbutton->texture=&playbtn[1];
|
||||||
|
buttondelay=5;
|
||||||
|
}else {
|
||||||
|
if(buttondelay<0) {
|
||||||
|
playbutton->texture=&playbtn[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
s.tick();
|
s.tick();
|
||||||
buttondelay--;
|
buttondelay--;
|
||||||
}
|
}
|
||||||
|
|
@ -243,12 +271,29 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
tiny::ErrorLevel tiny::level{6};
|
tiny::ErrorLevel tiny::level{8};
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
nete.start();
|
|
||||||
nete.github();
|
|
||||||
tiny::startup((char*)"enginend test",(char*)"1.0");
|
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;
|
test e;
|
||||||
e.boot();
|
e.boot();
|
||||||
|
|
||||||
|
|
@ -290,5 +335,8 @@ int main(int argc, char *argv[]) {
|
||||||
tickthread.join();
|
tickthread.join();
|
||||||
|
|
||||||
e.exit();
|
e.exit();
|
||||||
|
config.setstring({"version"},nete.currentversion);
|
||||||
|
config.save();
|
||||||
|
config.close();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -29,29 +29,59 @@ struct netio {
|
||||||
std::string url="https://github.com/kin-fuyuki/forespend_cpp/releases/download/";
|
std::string url="https://github.com/kin-fuyuki/forespend_cpp/releases/download/";
|
||||||
std::vector<std::string> *versionhistory;
|
std::vector<std::string> *versionhistory;
|
||||||
std::string changelog="could not connect to github\nplease check your internet connection";
|
std::string changelog="could not connect to github\nplease check your internet connection";
|
||||||
|
std::string currentversion="NULL";
|
||||||
|
std::string newestversion="";
|
||||||
|
|
||||||
void start() {
|
void start() {
|
||||||
|
const int MAX_RETRIES = 3;
|
||||||
|
int attempts = 0;
|
||||||
|
bool download_success = false;
|
||||||
|
|
||||||
|
while (attempts < MAX_RETRIES && !download_success) {
|
||||||
CURL* curltdf = curl_easy_init();
|
CURL* curltdf = curl_easy_init();
|
||||||
CURLcode ret;
|
|
||||||
if (curltdf) {
|
if (curltdf) {
|
||||||
FILE* history = fopen("versions.tdf", "wb");
|
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_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_WRITEFUNCTION, write_data);
|
||||||
curl_easy_setopt(curltdf, CURLOPT_WRITEDATA, history);
|
curl_easy_setopt(curltdf, CURLOPT_WRITEDATA, history);
|
||||||
ret = curl_easy_perform(curltdf);
|
|
||||||
curl_easy_cleanup(curltdf);
|
|
||||||
fclose(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;
|
tiny::TDF_FILE fetchversions;
|
||||||
fetchversions.filepath = "versions.tdf";
|
fetchversions.filepath = "versions.tdf";
|
||||||
fetchversions.read();
|
fetchversions.read();
|
||||||
boost::unordered_map<std::string,tiny::TDF_DATA>* foreversions= fetchversions.getclass({"forespend"});
|
|
||||||
|
boost::unordered_map<std::string, tiny::TDF_DATA>* foreversions = fetchversions.getclass({"forespend"});
|
||||||
|
if (!foreversions) return;
|
||||||
|
|
||||||
std::vector<std::string> versions;
|
std::vector<std::string> versions;
|
||||||
for (auto version:*foreversions) {
|
for (auto& version : *foreversions) {
|
||||||
tiny::error("path: %s",version.first.c_str());
|
if (version.second.type == tiny::TDF_Type::TDF_DEFINES) {
|
||||||
if (version.second.type==tiny::TDF_Type::TDF_DEFINES) {
|
versions = *(std::vector<std::string>*)version.second.datapointer;
|
||||||
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) {
|
std::sort(versions.begin(), versions.end(), [](const std::string& a, const std::string& b) {
|
||||||
int ra = 0, rb = 0;
|
int ra = 0, rb = 0;
|
||||||
float va = 0.0f, vb = 0.0f;
|
float va = 0.0f, vb = 0.0f;
|
||||||
|
|
@ -64,16 +94,22 @@ struct netio {
|
||||||
if (pa != pb) return pa > pb;
|
if (pa != pb) return pa > pb;
|
||||||
return rea < reb;
|
return rea < reb;
|
||||||
});
|
});
|
||||||
tiny::success("\n\nforespend versions:");
|
|
||||||
for (auto version:versions) {
|
|
||||||
|
|
||||||
tiny::warning("%s",version.c_str());
|
this->newestversion = versions[0]; // Sort is descending, index 0 is newest
|
||||||
}
|
if (this->newestversion != "") {
|
||||||
tiny::success("found\n\n");
|
this->currentversion = newestversion;
|
||||||
versionhistory=&versions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
void github() {
|
||||||
CURL* curl;
|
CURL* curl;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ inline const char* BOLDWHITE="\033[1m\033[37m";
|
||||||
va_end (arg);
|
va_end (arg);
|
||||||
|
|
||||||
inline void echo(const char * info,...){
|
inline void echo(const char * info,...){
|
||||||
if (level.value==4)
|
if (level.value>=4)
|
||||||
{
|
{
|
||||||
va_list arg;
|
va_list arg;
|
||||||
std::string mixer=info;
|
std::string mixer=info;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue