summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2008-11-04 05:52:02 +0000
committerJared Adams <jaxad0127@gmail.com>2008-11-04 05:52:02 +0000
commit56039e23308cbe9faee378a20100aa3adc1b94c2 (patch)
treeccb4d4b6d7359bee4e07633cc9fda3ce10925fa1
parentc0ee37d564ad0239b928d60149e1e50bb1d0c4e7 (diff)
downloadtmwa-56039e23308cbe9faee378a20100aa3adc1b94c2.tar.gz
tmwa-56039e23308cbe9faee378a20100aa3adc1b94c2.tar.bz2
tmwa-56039e23308cbe9faee378a20100aa3adc1b94c2.tar.xz
tmwa-56039e23308cbe9faee378a20100aa3adc1b94c2.zip
Commit Mantis 414: Tool for mapping item IDs to a particular item ID
-rw-r--r--src/tool/Makefile8
-rw-r--r--src/tool/itemfrob.c118
-rw-r--r--src/tool/mapfrob.c126
3 files changed, 251 insertions, 1 deletions
diff --git a/src/tool/Makefile b/src/tool/Makefile
index 8734041..4ddcf8b 100644
--- a/src/tool/Makefile
+++ b/src/tool/Makefile
@@ -1,6 +1,12 @@
+CC=gcc -m32 -O0 -g
+BDIR=..
+COBJS=${BDIR}/common/timer.o ${BDIR}/common/malloc.o ${BDIR}/common/socket.o ${BDIR}/common/lock.o ${BDIR}/common/db.o ${BDIR}/char/int_pet.o ${BDIR}/char/int_storage.o ${BDIR}/char/inter.o ${BDIR}/char/int_party.o ${BDIR}/char/int_guild.o
+
all:
$(CC) -o adduser adduser.c
+ $(CC) -I ${BDIR}/char -I ${BDIR}/common itemfrob.c -o itemfrob ${COBJS}
+ $(CC) -I ${BDIR}/char -I ${BDIR}/common mapfrob.c -o mapfrob ${COBJS}
clean:
- rm -f adduser
+ rm -f adduser itemfrob mapfrop
rm -f *.exe
diff --git a/src/tool/itemfrob.c b/src/tool/itemfrob.c
new file mode 100644
index 0000000..999834c
--- /dev/null
+++ b/src/tool/itemfrob.c
@@ -0,0 +1,118 @@
+// Compile with
+// gcc -m32 -I src/char -I src/common charfrob.c -o charfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_pet.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "../common/mmo.h"
+#include "../char/char.c"
+
+// Well, this is not terribly elegant, but I don't have that much time.
+#define MAX_ITEM_ID 65535
+int inv_translate[MAX_ITEM_ID];
+
+void
+transform_char(struct mmo_charstatus *p)
+{
+ int k;
+ for (k = 0; k < MAX_INVENTORY; k++)
+ p->inventory[k].nameid = inv_translate[p->inventory[k].nameid];
+}
+
+int mmo_char_convert()
+{
+ char line[965536];
+ int ret;
+ struct mmo_charstatus char_dat;
+ FILE *ifp,*ofp;
+
+ ifp=stdin;
+ ofp=stdout;
+ while(fgets(line,65535,ifp)){
+ memset(&char_dat,0,sizeof(struct mmo_charstatus));
+ ret=mmo_char_fromstr(line,&char_dat);
+ if(ret){
+ transform_char(&char_dat);
+ mmo_char_tostr(line,&char_dat);
+ fprintf(ofp,"%s" RETCODE,line);
+ }
+ }
+ fcloseall();
+ return 0;
+}
+
+#define PARSE_MODE_NEXTNUM 0
+#define PARSE_MODE_RANGE 1
+
+int init(char *source, char *dest)
+{
+ int i;
+ char *end_of_num;
+ int dest_nr = strtol(dest, &end_of_num, 0);
+ int range_start;
+ int mode = PARSE_MODE_NEXTNUM;
+
+ if (*end_of_num) {
+ fprintf(stderr, "Invalid inventory ID: `%s'\n", dest);
+ return 1;
+ }
+
+ /* init */
+ for (i = 0; i < MAX_ITEM_ID; i++)
+ inv_translate[i] = i;
+
+ while (*source) {
+ int nr = strtol(source, &end_of_num, 0);
+ char sep;
+
+ if (end_of_num == source) {
+ fprintf(stderr, "Invalid source range description: `%s'\n", source);
+ return 1;
+ }
+
+ switch (mode) {
+ case PARSE_MODE_NEXTNUM:
+ inv_translate[nr] = dest_nr;
+ break;
+ case PARSE_MODE_RANGE:
+ for (i = range_start; i <= nr; i++)
+ inv_translate[i] = dest_nr;
+ break;
+ default: fprintf(stderr, "Internal error at %d\n", __LINE__);
+ return 1;
+ };
+
+ sep = *end_of_num++;
+
+ switch (sep) {
+ case '-':
+ range_start = nr;
+ mode = PARSE_MODE_RANGE; break;
+ case ',': mode = PARSE_MODE_NEXTNUM; break;
+ case 0: return 0;
+ default: fprintf(stderr, "Invalid token in range spec: `%c'\n", sep);
+ return 1;
+ }
+
+ source = end_of_num;
+ }
+ return 0;
+}
+
+int main(int argc,char *argv[])
+{
+ if(argc < 3) {
+ printf("Usage: %s <inventory ID input range> <inventory ID output>\n", argv[0]);
+ printf("e.g., %s 501-555 701\n", argv[0]);
+ exit(0);
+ }
+ if (init(argv[1], argv[2]))
+ return 1;
+
+ mmo_char_convert();
+
+ return 0;
+}
+
+
+/* satisfy linker */
+void set_termfunc(void (*termfunc)(void)) {};
diff --git a/src/tool/mapfrob.c b/src/tool/mapfrob.c
new file mode 100644
index 0000000..7173f0b
--- /dev/null
+++ b/src/tool/mapfrob.c
@@ -0,0 +1,126 @@
+// Compile with
+// gcc -m32 -I src/char -I src/common charfrob.c -o charfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_pet.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "../common/mmo.h"
+#include "../char/char.c"
+
+// Well, this is not terribly elegant, but I don't have that much time.
+#define MAX_MAP 1024
+#define MAP_NAME_SIZE 32
+int maps_nr = 0;
+struct {
+ char old[MAP_NAME_SIZE], new[MAP_NAME_SIZE];
+} maps[MAX_MAP];
+
+void
+transform_point(struct point *p)
+{
+ int k;
+
+ if (!p->map[0])
+ return;
+
+ for (k = 0; k < maps_nr; k++)
+ if (!strcmp(p->map, maps[k].old)) {
+ strcpy(p->map, maps[k].new);
+ return;
+ }
+
+ fprintf(stderr, "Warning: untranslated map `%s'\n", p->map);
+}
+
+void
+transform_char(struct mmo_charstatus *p)
+{
+ int i;
+
+ transform_point(&p->last_point);
+ transform_point(&p->save_point);
+
+ for (i = 0; i < 10; i++)
+ transform_point(&p->memo_point[i]);
+}
+
+int mmo_char_convert()
+{
+ char line[965536];
+ int ret;
+ struct mmo_charstatus char_dat;
+ FILE *ifp,*ofp;
+
+ ifp=stdin;
+ ofp=stdout;
+ while(fgets(line,65535,ifp)){
+ memset(&char_dat,0,sizeof(struct mmo_charstatus));
+ ret=mmo_char_fromstr(line,&char_dat);
+ if(ret){
+ transform_char(&char_dat);
+ mmo_char_tostr(line,&char_dat);
+ fprintf(ofp,"%s" RETCODE,line);
+ }
+ }
+ fcloseall();
+ return 0;
+}
+
+#define PARSE_MODE_NEXTNUM 0
+#define PARSE_MODE_RANGE 1
+
+int init(int count, char **translates)
+{
+ int i;
+ char *suffix = ".gat";
+
+ for (i = 0; i < count; i++) {
+ char *src = translates[i];
+ char *dest = strchr(src, ':');
+
+ if (!dest) {
+ fprintf(stderr, "Missing colon in: `%s'\n", src);
+ return 1;
+ }
+
+ *dest++ = 0;
+
+ if (strlen(src) + strlen(suffix) >= MAP_NAME_SIZE) {
+ fprintf(stderr, "Map name prefix too long: `%s'\n", src);
+ return 1;
+ }
+
+ if (strlen(dest) + strlen(suffix) >= MAP_NAME_SIZE) {
+ fprintf(stderr, "Map name prefix too long: `%s'\n", dest);
+ return 1;
+ }
+
+ strncpy(maps[maps_nr].old, src, MAP_NAME_SIZE);
+ strcat(maps[maps_nr].old, suffix);
+ strncpy(maps[maps_nr].new, dest, MAP_NAME_SIZE);
+ strcat(maps[maps_nr].new, suffix);
+
+ ++maps_nr;
+ }
+
+ return 0;
+}
+
+int main(int argc,char *argv[])
+{
+ if(argc < 2) {
+ printf("Usage: %s oldmap0:newmap0 oldmap1:newmap1 ...\n", argv[0]);
+ printf("e.g., %s new_1-1:001-2 new_2-1:001-1\n", argv[0]);
+ puts("The extension `.gat' is appended implicitly.");
+ exit(0);
+ }
+ if (init(argc - 1, argv + 1))
+ return 1;
+
+ mmo_char_convert();
+
+ return 0;
+}
+
+
+/* satisfy linker */
+void set_termfunc(void (*termfunc)(void)) {};