view Chest.cpp @ 0:8b8875f5b359

Initial commit
author Nomad
date Fri, 05 Oct 2012 16:07:14 +0200
parents
children
line wrap: on
line source

#include <stdio.h>

#include "Chest.h"
#include "FrameTableInc.h"
#include "Allocator.h"

#include "mm7_data.h"




size_t uNumChests; // idb
struct ChestList *pChestList;
Chest pChests[20];





//----- (00458B03) --------------------------------------------------------
void ChestList::ToFile()
{
  ChestList *v1; // esi@1
  FILE *v2; // eax@1
  FILE *v3; // edi@1

  v1 = this;
  v2 = fopen("data\\dchest.bin", "wb");
  v3 = v2;
  if ( !v2 )
    Abortf("Unable to save dchest.bin!");
  fwrite(v1, 4u, 1u, v2);
  fwrite(v1->pChests, 0x24u, v1->uNumChests, v3);
  fclose(v3);
}


//----- (00458B4F) --------------------------------------------------------
void ChestList::FromFile(void *pSerialized)
{
  uNumChests = *(int *)pSerialized;
  pChests = (ChestDesc *)pAllocator->AllocNamedChunk(pChests, 36 * uNumChests, "Chest Descrip");
  memcpy(pChests, (char *)pSerialized + 4, 36 * uNumChests);
}


//----- (00458B9C) --------------------------------------------------------
int ChestList::FromFileTxt(const char *Args)
{
  ChestList *v2; // ebx@1
  __int32 v3; // edi@1
  FILE *v4; // eax@1
  unsigned int v5; // esi@3
  const void *v6; // ST18_4@9
  void *v7; // eax@9
  FILE *v8; // ST0C_4@11
  char *i; // eax@11
  char v10; // al@14
  const char *v11; // ST14_4@14
  char v12; // al@14
  const char *v13; // ST10_4@14
  char Buf; // [sp+8h] [bp-2F0h]@3
  FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4
  FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4
  FILE *File; // [sp+2F4h] [bp-4h]@1
  unsigned int Argsa; // [sp+300h] [bp+8h]@3

  v2 = this;
  pAllocator->FreeChunk(this->pChests);
  v3 = 0;
  v2->pChests = 0;
  v2->uNumChests = 0;
  v4 = fopen(Args, "r");
  File = v4;
  if ( !v4 )
    Abortf("ChestDescriptionList::load - Unable to open file: %s.");
  v5 = 0;
  Argsa = 0;
  if ( fgets(&Buf, 490, v4) )
  {
    do
    {
      *strchr(&Buf, 10) = 0;
      memcpy(&v17, texture_frame_table_txt_parser(&Buf, &v16), sizeof(v17));
      if ( v17.field_0 && *v17.pProperties[0] != 47 )
        ++Argsa;
    }
    while ( fgets(&Buf, 490, File) );
    v5 = Argsa;
    v3 = 0;
  }
  v6 = v2->pChests;
  v2->uNumChests = v5;
  v7 = pAllocator->AllocNamedChunk(v6, 36 * v5, "Chest Descrip");
  v2->pChests = (ChestDesc *)v7;
  if ( v7 == (void *)v3 )
    Abortf("ChestDescriptionList::load - Out of Memory!");
  memset(v7, v3, 36 * v2->uNumChests);
  v8 = File;
  v2->uNumChests = v3;
  fseek(v8, v3, v3);
  for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
  {
    *strchr(&Buf, 10) = 0;
    memcpy(&v17, texture_frame_table_txt_parser(&Buf, &v16), sizeof(v17));
    if ( v17.field_0 && *v17.pProperties[0] != 47 )
    {
      strcpy(v2->pChests[v2->uNumChests].pName, v17.pProperties[0]);
      v10 = atoi(v17.pProperties[1]);
      v11 = v17.pProperties[2];
      v2->pChests[v2->uNumChests].uWidth = v10;
      v12 = atoi(v11);
      v13 = v17.pProperties[3];
      v2->pChests[v2->uNumChests].uHeight = v12;
      v2->pChests[v2->uNumChests++].uTextureID = atoi(v13);
    }
  }
  fclose(File);
  return 1;
}