Skip to content

Commit

Permalink
dat2json, ...: Adding a (broken) standalone dat2json_cli.
Browse files Browse the repository at this point in the history
It currently does not build with Bazel, and crashes when built with `make`.

Tolerable for merging of the branch, however: issue can be addressed later.

A useful side effect is that more useless GUI-dependencies have been removed,
such as an attempt to load graphics in `objects.cpp`.
  • Loading branch information
ivucica committed Sep 15, 2023
1 parent bbd6867 commit 542ed32
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SDL_gfx-2.0.24/
*.o
yatc
yatc_cli
dat2json_cli
Tibia.pic
Tibia.dat
Tibia.spr
Expand Down
110 changes: 110 additions & 0 deletions cli/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,113 @@ filegroup(
"//net:protocolgame854.cpp",
],
)

cc_library(
name = "dat2json_cli_lib",
defines = ["CLI_ONLY=1", "BAZEL_BUILD=1"] + select({
"//conditions:default": [],
"//:windows": ["WIN32=1",],
"//:windows_msys": ["WIN32=1",],
"//:windows_msvc": ["WIN32=1",],
}),
srcs = [
"creatureui.cpp", "//:creatureui.h",
"thingui.cpp", "//:thingui.h",
"effectui.cpp", "//:effectui.h",
"objects.cpp", "//:objects.h",
"distanceui.cpp", "//:distanceui.h",
"itemui.cpp", "//:itemui.h",
"notifications.cpp", "//:notifications.h",

"//gamecontent:inventory.cpp",
"//gamecontent:globalvars.cpp",
"//gamecontent:creature.cpp",
"//gamecontent:map.cpp",
"//gamecontent:container.cpp",

"//:stdinttypes.h",
"//:sprite.h",
"//:defines.h",

"//gamecontent:creature.h",
"//gamecontent:thing.h",
"//gamecontent:enums.h",
"//gamecontent:position.h",
"//gamecontent:globalvars.h",
"//gamecontent:container.h",
"//gamecontent:itemcontainer.h",
"//gamecontent:shop.h",
"//gamecontent:inventory.h",
"//gamecontent:map.h",
"//gamecontent:item.h",
"//gamecontent:viplist.h",

"//net:encryption.cpp",
"//net:networkmessage.cpp",
"//net:connection.cpp",

"//net:connection.h",
"//net:networkmessage.h",
"//net:encryption.h",
"//net:protocolconfig.h",
"//net:protocolconfig.cpp",
"//net:protocolgame.h",
"//net:protocollogin.h",
"//net:protocollogin.cpp",
#"//net:rsa.h",
#"//net:rsa.cpp",

"//:util.cpp",
"//:util.h",
"//:product.h",
"//:macutil.h",

":protocolgamehdrs",
"dat2json_cli.cpp",
],
deps = [
"//:debugprint",
"//:fassert",

"//net:enum_hdr",
"@tommath//:tommath",
#"//:yatc_lib", # We could pull in far less stuff. See Makefile.
] + select({
"//:darwin": [
"@libsdl12//:sdlmain",
"//:macclipboard",
"//:macutil",
"@libsdl12//:sdl", # util.h is pulling in SDL/SDL_endian.h
],
"//conditions:default": [
"@libsdl12//:sdl", # util.h is pulling in SDL/SDL_endian.h
"@libsdl12//:sdlmain", # and because of that we pull in SDL_main too
],
}) + select({
":login_only": [],
"//conditions:default": [
"//net:protocols", # FIXME: This is pulling in REALLY a lot, incl chunks/all of glict. And yet it doesn't build.
],
}),
data = [
"@tibia854//:Tibia.dat",
],
copts = select({
"//conditions:default": ["-isystem external/tommath"],
"//:windows": ["-I external/tommath"],
"//:windows_msvc": ["-I external/tommath"],
}),
linkopts = select({
"//conditions:default": [],
"//:windows": ["-DEFAULTLIB:ws2_32", "-DEFAULTLIB:shell32"],
"//:windows_msvc": ["-DEFAULTLIB:ws2_32", "-DEFAULTLIB:shell32"],
}),
)

cc_binary(
name = "dat2json_cli",
deps = [
":dat2json_cli_lib",
],
)

11 changes: 7 additions & 4 deletions cli/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
CXXFLAGS=-DCLI_ONLY -DLOGIN_ONLY -DHAVE_GMP_H=1
CFLAGS=-DCLI_ONLY -DLOGIN_ONLY -DHAVE_GMP_H=1
OBJS=yatc_cli.o ../net/connection.o ../net/networkmessage.o ../debugprint.o ../util.o notifications.o ../gamecontent/creature.o ../gamecontent/container.o ../gamecontent/globalvars.o ../gamecontent/inventory.o ../gamecontent/map.o creatureui.o thingui.o distanceui.o effectui.o objects.o ../net/protocolconfig.o ../net/rsa.o ../net/encryption.o ../net/protocollogin.o
yatc_cli: $(OBJS)
g++ $(OBJS) -lSDL -lgmp -o yatc_cli
OBJS=../net/connection.o ../net/networkmessage.o ../debugprint.o ../util.o notifications.o ../gamecontent/creature.o ../gamecontent/container.o ../gamecontent/globalvars.o ../gamecontent/inventory.o ../gamecontent/map.o creatureui.o thingui.o distanceui.o effectui.o ../net/protocolconfig.o ../net/rsa.o ../net/encryption.o ../net/protocollogin.o
all: yatc_cli dat2json_cli
yatc_cli: $(OBJS) yatc_cli.o objects.o
g++ yatc_cli.o $(OBJS) objects.o -lSDL -lgmp -o yatc_cli
dat2json_cli: $(OBJS) dat2json_cli.o ../objects.o ../options.o ../confighandler.o
g++ dat2json_cli.o ../objects.o ../options.o ../confighandler.o $(OBJS) -lSDL -lgmp -o dat2json_cli
clean:
rm $(OBJS) yatc_cli
rm $(OBJS) yatc_cli yatc_cli.o dat2json_cli dat2json_cli.o ../objects.o objects.o ../options.o ../confighandler.o
53 changes: 53 additions & 0 deletions cli/dat2json_cli.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//////////////////////////////////////////////////////////////////////
// Yet Another Tibia Client
//////////////////////////////////////////////////////////////////////
// CLI version.
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////

#include <string>
#include <iostream>
#include <fstream>
#include "../util.h"
#include "../objects.h"
#include "../options.h"
#include "../net/connection.h"

#if BAZEL_BUILD && WIN32
#include <SDL/SDL.h> // Give SDL a chance to rename main() for sake of SDL_main.
#endif

std::string g_recordfilename="debugrecord.rec";

unsigned int g_frameTime = 0;
unsigned int g_frameDiff = 0;
Connection *g_connection = NULL;

int main(int argc, char** argv) {
auto i = Objects::getInstance();
if (argc != 3) {
fprintf(stderr, "usage: %s datfile jsonfile\n", argv[0]);
return 1;
}
i->loadDat(argv[1]);

std::ofstream outFile;
outFile.open(argv[2]);
i->asJSON(outFile);
outFile.close();

return 0;
}
12 changes: 7 additions & 5 deletions objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@

#include <iostream>
#include "objects.h"
#ifndef CLI_ONLY
#include "engine.h" // used to create engine specific sprites
#else
#include <map>
#include "fassert.h"
#endif
#include "util.h"
#include "options.h"
#include "net/protocolconfig.h"
Expand Down Expand Up @@ -112,7 +117,9 @@ void ObjectType::loadGfx()

if (m_gfx.size() != numsprites) { // graphics not loaded yet?
for(uint32_t i = 0; i < numsprites; i++){
#ifndef CLI_ONLY
m_gfx.insert(m_gfx.end(), g_engine->createSprite("Tibia.spr", imageData[i]));
#endif
}
}

Expand Down Expand Up @@ -541,11 +548,6 @@ bool Objects::load780plus(const char* filename)
fclose(fp);
m_datLoaded = true;

std::ofstream outFile;
outFile.open("/tmp/Tibia.dat.json");
asJSON(outFile);
outFile.close();

return true;
}

Expand Down
4 changes: 3 additions & 1 deletion objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ class Objects
Array<ObjectType*> m_effect;
Array<ObjectType*> m_distance;

void asJSON(std::ostream &o) ;
public:
// Public for use in dat2json_cli
void asJSON(std::ostream &o);
};

#endif

0 comments on commit 542ed32

Please sign in to comment.