summaryrefslogtreecommitdiff
path: root/src/tool/moneycount/athena_text.cpp
blob: 8cf545743ea7415f0005af097b1983d5b47a4b38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#include "athena_text.hpp"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "mmo.hpp"

//-------------------------------------------------------------------------
// Function to set the character from the line (at read of characters file)
//-------------------------------------------------------------------------
int mmo_char_fromstr (char *str, struct mmo_charstatus *p)
{
    int  tmp_int[256];
    int  set, next, len, i;

    // initilialise character
    memset (p, '\0', sizeof (struct mmo_charstatus));

    // If it's not char structure of version 1008 and after
    if ((set = sscanf (str, "%d\t%d,%d\t%[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%[^,],%d,%d\t%[^,],%d,%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], p->name,  //
                       &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13], &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20], &tmp_int[21], &tmp_int[22], &tmp_int[23],   //
                       &tmp_int[24], &tmp_int[25], &tmp_int[26], &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], &tmp_int[34], p->last_point.map, &tmp_int[35], &tmp_int[36], //
                       p->save_point.map, &tmp_int[37], &tmp_int[38],
                       &tmp_int[39], &next)) != 43)
    {
        tmp_int[39] = 0;        // partner id
        // If not char structure from version 384 to 1007
        if ((set = sscanf (str, "%d\t%d,%d\t%[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%[^,],%d,%d\t%[^,],%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], p->name, //
                           &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13], &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20], &tmp_int[21], &tmp_int[22], &tmp_int[23],   //
                           &tmp_int[24], &tmp_int[25], &tmp_int[26], &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], &tmp_int[34], p->last_point.map, &tmp_int[35], &tmp_int[36], //
                           p->save_point.map, &tmp_int[37], &tmp_int[38],
                           &next)) != 42)
        {
            // It's char structure of a version before 384
            tmp_int[26] = 0;    // pet id
            set = sscanf (str, "%d\t%d,%d\t%[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%[^,],%d,%d\t%[^,],%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], p->name, //
                          &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13], &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20], &tmp_int[21], &tmp_int[22], &tmp_int[23],    //
                          &tmp_int[24], &tmp_int[25],   //
                          &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], &tmp_int[34], p->last_point.map, &tmp_int[35], &tmp_int[36],    //
                          p->save_point.map, &tmp_int[37], &tmp_int[38],
                          &next);
            set += 2;
            //printf("char: old char data ver.1\n");
            // Char structure of version 1007 or older
        }
        else
        {
            set++;
            //printf("char: old char data ver.2\n");
        }
        // Char structure of version 1008+
    }
    else
    {
        //printf("char: new char data ver.3\n");
    }
    if (set != 43)
        return 0;

    p->char_id = tmp_int[0];
    p->account_id = tmp_int[1];
    p->char_num = tmp_int[2];
    p->classb = tmp_int[3];
    p->base_level = tmp_int[4];
    p->job_level = tmp_int[5];
    p->base_exp = tmp_int[6];
    p->job_exp = tmp_int[7];
    p->zeny = tmp_int[8];
    p->hp = tmp_int[9];
    p->max_hp = tmp_int[10];
    p->sp = tmp_int[11];
    p->max_sp = tmp_int[12];
    p->str = tmp_int[13];
    p->agi = tmp_int[14];
    p->vit = tmp_int[15];
    p->int_ = tmp_int[16];
    p->dex = tmp_int[17];
    p->luk = tmp_int[18];
    p->status_point = tmp_int[19];
    p->skill_point = tmp_int[20];
    p->option = tmp_int[21];
    p->karma = tmp_int[22];
    p->manner = tmp_int[23];
    p->party_id = tmp_int[24];
    p->guild_id = tmp_int[25];
//  p->pet_id = tmp_int[26];
    p->hair = tmp_int[27];
    p->hair_color = tmp_int[28];
    p->clothes_color = tmp_int[29];
    p->weapon = tmp_int[30];
    p->shield = tmp_int[31];
    p->head_top = tmp_int[32];
    p->head_mid = tmp_int[33];
    p->head_bottom = tmp_int[34];
    p->last_point.x = tmp_int[35];
    p->last_point.y = tmp_int[36];
    p->save_point.x = tmp_int[37];
    p->save_point.y = tmp_int[38];
    p->partner_id = tmp_int[39];

    if (str[next] == '\n' || str[next] == '\r')
        return 1;               // ?V?K?f?[?^

    next++;

    for (i = 0; str[next] && str[next] != '\t'; i++)
    {
        if (sscanf
            (str + next, "%[^,],%d,%d%n", p->memo_point[i].map, &tmp_int[0],
             &tmp_int[1], &len) != 3)
            return -3;
        p->memo_point[i].x = tmp_int[0];
        p->memo_point[i].y = tmp_int[1];
        next += len;
        if (str[next] == ' ')
            next++;
    }

    next++;

    for (i = 0; str[next] && str[next] != '\t'; i++)
    {
        if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
                    &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
                    &tmp_int[4], &tmp_int[5], &tmp_int[6],
                    &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10],
                    &tmp_int[11], &len) == 12)
        {
            // do nothing, it's ok
        }
        else if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
                         &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
                         &tmp_int[4], &tmp_int[5], &tmp_int[6],
                         &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10],
                         &len) == 11)
        {
            tmp_int[11] = 0;    // broken doesn't exist in this version -> 0
        }
        else                    // invalid structure
            return -4;
        p->inventory[i].id = tmp_int[0];
        p->inventory[i].nameid = tmp_int[1];
        p->inventory[i].amount = tmp_int[2];
        p->inventory[i].equip = tmp_int[3];
        p->inventory[i].identify = tmp_int[4];
        p->inventory[i].refine = tmp_int[5];
        p->inventory[i].attribute = tmp_int[6];
        p->inventory[i].card[0] = tmp_int[7];
        p->inventory[i].card[1] = tmp_int[8];
        p->inventory[i].card[2] = tmp_int[9];
        p->inventory[i].card[3] = tmp_int[10];
        p->inventory[i].broken = tmp_int[11];
        next += len;
        if (str[next] == ' ')
            next++;
    }

    next++;

    for (i = 0; str[next] && str[next] != '\t'; i++)
    {
        if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
                    &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
                    &tmp_int[4], &tmp_int[5], &tmp_int[6],
                    &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10],
                    &tmp_int[11], &len) == 12)
        {
            // do nothing, it's ok
        }
        else if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
                         &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
                         &tmp_int[4], &tmp_int[5], &tmp_int[6],
                         &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10],
                         &len) == 11)
        {
            tmp_int[11] = 0;    // broken doesn't exist in this version -> 0
        }
        else                    // invalid structure
            return -5;
        p->cart[i].id = tmp_int[0];
        p->cart[i].nameid = tmp_int[1];
        p->cart[i].amount = tmp_int[2];
        p->cart[i].equip = tmp_int[3];
        p->cart[i].identify = tmp_int[4];
        p->cart[i].refine = tmp_int[5];
        p->cart[i].attribute = tmp_int[6];
        p->cart[i].card[0] = tmp_int[7];
        p->cart[i].card[1] = tmp_int[8];
        p->cart[i].card[2] = tmp_int[9];
        p->cart[i].card[3] = tmp_int[10];
        p->cart[i].broken = tmp_int[11];
        next += len;
        if (str[next] == ' ')
            next++;
    }

    next++;

    for (i = 0; str[next] && str[next] != '\t'; i++)
    {
        if (sscanf (str + next, "%d,%d%n", &tmp_int[0], &tmp_int[1], &len) !=
            2)
            return -6;
        p->skill[tmp_int[0]].id = tmp_int[0];
        p->skill[tmp_int[0]].lv = tmp_int[1] & 0xffff;
        p->skill[tmp_int[0]].flags = ((tmp_int[1] >> 16) & 0xffff);
        next += len;
        if (str[next] == ' ')
            next++;
    }

    next++;

    for (i = 0;
         str[next] && str[next] != '\t' && str[next] != '\n'
         && str[next] != '\r'; i++)
    {                           // global_reg?????O??athena.txt????^????'\n'?`?F?b?N
        if (sscanf
            (str + next, "%[^,],%d%n", p->global_reg[i].str,
             &p->global_reg[i].value, &len) != 2)
        {
            // because some scripts are not correct, the str can be "". So, we must check that.
            // If it's, we must not refuse the character, but just this REG value.
            // Character line will have something like: nov_2nd_cos,9 ,9 nov_1_2_cos_c,1 (here, ,9 is not good)
            if (str[next] == ','
                && sscanf (str + next, ",%d%n", &p->global_reg[i].value,
                           &len) == 1)
                i--;
            else
                return -7;
        }
        next += len;
        if (str[next] == ' ')
            next++;
    }
    p->global_reg_num = i;

    return 1;
}

int accreg_fromstr (char *str, struct accreg *reg)
{
    int  j, v, n;
    char buf[128];
    const char *p = str;

     if (sscanf (p, "%d\t%n", &reg->account_id, &n) != 1
         || reg->account_id <= 0)
         return 0;

     for (j = 0, p += n; j < ACCOUNT_REG_NUM; j++, p += n)
     {
         if (sscanf (p, "%[^,],%d %n", buf, &v, &n) != 2)
             break;
         memcpy (reg->reg[j].str, buf, 32);
         reg->reg[j].value = v;
     }
     reg->reg_num = j;

     return 1;
}