Mercurial > mm7
comparison Chest.cpp @ 0:9c0607679772
init
author | Ritor1 |
---|---|
date | Sat, 12 Jan 2013 09:45:18 +0600 |
parents | |
children | 80a5aab68b67 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9c0607679772 |
---|---|
1 #include <stdio.h> | |
2 | |
3 #include "Chest.h" | |
4 #include "FrameTableInc.h" | |
5 #include "Allocator.h" | |
6 | |
7 #include "mm7_data.h" | |
8 | |
9 | |
10 | |
11 | |
12 size_t uNumChests; // idb | |
13 struct ChestList *pChestList; | |
14 Chest pChests[20]; | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 //----- (00458B03) -------------------------------------------------------- | |
21 void ChestList::ToFile() | |
22 { | |
23 ChestList *v1; // esi@1 | |
24 FILE *v2; // eax@1 | |
25 FILE *v3; // edi@1 | |
26 | |
27 v1 = this; | |
28 v2 = fopen("data\\dchest.bin", "wb"); | |
29 v3 = v2; | |
30 if ( !v2 ) | |
31 Abortf("Unable to save dchest.bin!"); | |
32 fwrite(v1, 4u, 1u, v2); | |
33 fwrite(v1->pChests, 0x24u, v1->uNumChests, v3); | |
34 fclose(v3); | |
35 } | |
36 | |
37 | |
38 //----- (00458B4F) -------------------------------------------------------- | |
39 void ChestList::FromFile(void *pSerialized) | |
40 { | |
41 uNumChests = *(int *)pSerialized; | |
42 pChests = (ChestDesc *)pAllocator->AllocNamedChunk(pChests, 36 * uNumChests, "Chest Descrip"); | |
43 memcpy(pChests, (char *)pSerialized + 4, 36 * uNumChests); | |
44 } | |
45 | |
46 | |
47 //----- (00458B9C) -------------------------------------------------------- | |
48 int ChestList::FromFileTxt(const char *Args) | |
49 { | |
50 ChestList *v2; // ebx@1 | |
51 __int32 v3; // edi@1 | |
52 FILE *v4; // eax@1 | |
53 unsigned int v5; // esi@3 | |
54 const void *v6; // ST18_4@9 | |
55 void *v7; // eax@9 | |
56 FILE *v8; // ST0C_4@11 | |
57 char *i; // eax@11 | |
58 char v10; // al@14 | |
59 const char *v11; // ST14_4@14 | |
60 char v12; // al@14 | |
61 const char *v13; // ST10_4@14 | |
62 char Buf; // [sp+8h] [bp-2F0h]@3 | |
63 FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4 | |
64 FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4 | |
65 FILE *File; // [sp+2F4h] [bp-4h]@1 | |
66 unsigned int Argsa; // [sp+300h] [bp+8h]@3 | |
67 | |
68 v2 = this; | |
69 pAllocator->FreeChunk(this->pChests); | |
70 v3 = 0; | |
71 v2->pChests = 0; | |
72 v2->uNumChests = 0; | |
73 v4 = fopen(Args, "r"); | |
74 File = v4; | |
75 if ( !v4 ) | |
76 Abortf("ChestDescriptionList::load - Unable to open file: %s."); | |
77 v5 = 0; | |
78 Argsa = 0; | |
79 if ( fgets(&Buf, 490, v4) ) | |
80 { | |
81 do | |
82 { | |
83 *strchr(&Buf, 10) = 0; | |
84 memcpy(&v17, texture_frame_table_txt_parser(&Buf, &v16), sizeof(v17)); | |
85 if ( v17.field_0 && *v17.pProperties[0] != 47 ) | |
86 ++Argsa; | |
87 } | |
88 while ( fgets(&Buf, 490, File) ); | |
89 v5 = Argsa; | |
90 v3 = 0; | |
91 } | |
92 v6 = v2->pChests; | |
93 v2->uNumChests = v5; | |
94 v7 = pAllocator->AllocNamedChunk(v6, 36 * v5, "Chest Descrip"); | |
95 v2->pChests = (ChestDesc *)v7; | |
96 if ( v7 == (void *)v3 ) | |
97 Abortf("ChestDescriptionList::load - Out of Memory!"); | |
98 memset(v7, v3, 36 * v2->uNumChests); | |
99 v8 = File; | |
100 v2->uNumChests = v3; | |
101 fseek(v8, v3, v3); | |
102 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
103 { | |
104 *strchr(&Buf, 10) = 0; | |
105 memcpy(&v17, texture_frame_table_txt_parser(&Buf, &v16), sizeof(v17)); | |
106 if ( v17.field_0 && *v17.pProperties[0] != 47 ) | |
107 { | |
108 strcpy(v2->pChests[v2->uNumChests].pName, v17.pProperties[0]); | |
109 v10 = atoi(v17.pProperties[1]); | |
110 v11 = v17.pProperties[2]; | |
111 v2->pChests[v2->uNumChests].uWidth = v10; | |
112 v12 = atoi(v11); | |
113 v13 = v17.pProperties[3]; | |
114 v2->pChests[v2->uNumChests].uHeight = v12; | |
115 v2->pChests[v2->uNumChests++].uTextureID = atoi(v13); | |
116 } | |
117 } | |
118 fclose(File); | |
119 return 1; | |
120 } |