annotate Chest.cpp @ 0:8b8875f5b359

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