OSDN Git Service

[fix] #41503 超能力者でゲームを開始しようとするとクラッシュ
[hengband/hengband.git] / src / load / load-util.c
1 #include "load/load-util.h"
2 #include "term/screen-processor.h"
3 #ifdef JP
4 #include "locale/japanese.h"
5 #endif
6
7 FILE *loading_savefile;
8 byte load_xor_byte; // Old "encryption" byte.
9 u32b v_check = 0L; // Simple "checksum" on the actual values.
10 u32b x_check = 0L; // Simple "checksum" on the encoded bytes.
11
12 /*
13  * Japanese Kanji code
14  * 0: Unknown
15  * 1: ASCII
16  * 2: EUC
17  * 3: SJIS
18  */
19 byte kanji_code = 0;
20
21 /*!
22  * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
23  * @param msg 表示文字列
24  * @return なし
25  * @details
26  * Avoid the top two lines, to avoid interference with "msg_print()".
27  */
28 void load_note(concptr msg)
29 {
30     static TERM_LEN y = 2;
31     prt(msg, y, 0);
32     if (++y >= 24)
33         y = 2;
34
35     term_fresh();
36 }
37
38 /*!
39  * @brief ロードファイルポインタから1バイトを読み込む
40  * @return 読み込んだバイト値
41  * @details
42  * The following functions are used to load the basic building blocks
43  * of savefiles.  They also maintain the "checksum" info for 2.7.0+
44  */
45 byte sf_get(void)
46 {
47     byte c = getc(loading_savefile) & 0xFF;
48     byte v = c ^ load_xor_byte;
49     load_xor_byte = c;
50
51     v_check += v;
52     x_check += load_xor_byte;
53     return v;
54 }
55
56 /*!
57  * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
58  * @param ip 読み込みポインタ
59  * @return なし
60  */
61 void rd_byte(byte *ip) { *ip = sf_get(); }
62
63 /*!
64  * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
65  * @param ip 読み込みポインタ
66  * @return なし
67  */
68 void rd_u16b(u16b *ip)
69 {
70     (*ip) = sf_get();
71     (*ip) |= ((u16b)(sf_get()) << 8);
72 }
73
74 /*!
75  * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
76  * @param ip 読み込みポインタ
77  * @return なし
78  */
79 void rd_s16b(s16b *ip) { rd_u16b((u16b *)ip); }
80
81 /*!
82  * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
83  * @param ip 読み込みポインタ
84  * @return なし
85  */
86 void rd_u32b(u32b *ip)
87 {
88     (*ip) = sf_get();
89     (*ip) |= ((u32b)(sf_get()) << 8);
90     (*ip) |= ((u32b)(sf_get()) << 16);
91     (*ip) |= ((u32b)(sf_get()) << 24);
92 }
93
94 /*!
95  * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
96  * @param ip 読み込みポインタ
97  * @return なし
98  */
99 void rd_s32b(s32b *ip) { rd_u32b((u32b *)ip); }
100
101 /*!
102  * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
103  * @param str 読み込みポインタ
104  * @param max 最大読み取りバイト数
105  * @return なし
106  */
107 void rd_string(char *str, int max)
108 {
109     for (int i = 0; TRUE; i++) {
110         byte tmp8u;
111         rd_byte(&tmp8u);
112         if (i < max)
113             str[i] = tmp8u;
114
115         if (!tmp8u)
116             break;
117     }
118
119     str[max - 1] = '\0';
120 #ifdef JP
121     switch (kanji_code) {
122 #ifdef SJIS
123     case 2:
124         euc2sjis(str);
125         break;
126 #endif
127
128 #ifdef EUC
129     case 3:
130         sjis2euc(str);
131         break;
132 #endif
133
134     case 0: {
135         byte code = codeconv(str);
136
137         /* 漢字コードが判明したら、それを記録 */
138         if (code)
139             kanji_code = code;
140
141         break;
142     }
143     default:
144         break;
145     }
146 #endif
147 }
148
149 /*!
150  * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
151  * @param n スキップバイト数
152  * @return なし
153  */
154 void strip_bytes(int n)
155 {
156     byte tmp8u;
157     while (n--)
158         rd_byte(&tmp8u);
159 }