-
Notifications
You must be signed in to change notification settings - Fork 5
/
ROMUpdate.cpp
109 lines (83 loc) · 3.85 KB
/
ROMUpdate.cpp
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
#include "Map.h"
#include "ROMUpdate.h"
#include "ROMData.h"
#include "TextUpdate.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
namespace ROMUpdate {
void ROMUpdateTextAndItems(vector<Lair> RandomizedLairList,
vector<Item> RandomizedItemList,
fstream &ROMFile,
long Seed) {
unsigned char ItemID;
unsigned char GemsExpValue[2];
unsigned char Byte;
int GemsExp_TensAndUnits;
/*************************/
/* Update Chest contents */
/*************************/
ROMFile.seekp (CHEST_DATA_ADDRESS, ios::beg);
bool DoubledChestDone = false;
for (int i=0; i<NUMBER_OF_CHESTS; i++) {
/* Put the cursor on the contents data for this chest */
ROMFile.seekp (3, ios::cur);
/* Update the contents */
ItemID = RandomizedItemList[i].Contents;
ROMFile.write((char*)(&ItemID), 1);
GemsExp_TensAndUnits = RandomizedItemList[i].GemsExp % 100;
GemsExpValue[0] = ConvertToHex(GemsExp_TensAndUnits);
GemsExpValue[1] = ConvertToHex((RandomizedItemList[i].GemsExp - GemsExp_TensAndUnits) / 100);
ROMFile.write((char*)(&GemsExpValue[0]), 2);
/* Chest at index 22 is doubled, so we have to double its replacing one */
if (i==22 && DoubledChestDone==false) {
i--;
DoubledChestDone = true;
}
/* Skip over FF bytes */
ROMFile.seekg (0, ios::cur);
do {
ROMFile.read ((char*)(&Byte), 1);
}
while (Byte == 0xFF);
ROMFile.seekp (-1, ios::cur);
}
/*************************************/
/* Full update of text and NPC items */
/*************************************/
NPCTextUpdateMain(RandomizedLairList, RandomizedItemList, ROMFile, Seed);
}
void ROMUpdateLairs(vector<Lair> RandomizedLairList, fstream &ROMFile) {
ROMFile.seekp (MONSTER_LAIR_DATA_ADDRESS, ios::beg);
for (int i=0; i<NUMBER_OF_LAIRS; i++) {
ROMFile.seekg(10, ios::cur);
/* Update the contents of this Monster Lair */
ROMFile.write((char*)(&RandomizedLairList[i].Act), 1);
ROMFile.write((char*)(&(RandomizedLairList[i].PositionData[0])), POSITION_DATA_SIZE);
ROMFile.seekp(2, ios::cur);
ROMFile.write((char*)(&(RandomizedLairList[i].Type[0])), LAIR_TYPE_SIZE);
ROMFile.seekp(1, ios::cur);
ROMFile.write((char*)(&RandomizedLairList[i].NbEnemies), 1);
ROMFile.write((char*)(&RandomizedLairList[i].SpawnRate), 1);
ROMFile.write((char*)(&RandomizedLairList[i].Enemy), 1);
ROMFile.seekp(1, ios::cur);
ROMFile.write((char*)(&RandomizedLairList[i].Orientation), 1);
ROMFile.seekp(8, ios::cur);
}
}
void ROMUpdateMapSprites(vector<Sprite> RandomizedSpriteList, fstream &ROMFile) {
int Address;
for (int SpriteIndex = 0; SpriteIndex < NUMBER_OF_SPRITES; ++SpriteIndex) {
/* Get the ROM address of this sprite data */
Address = RandomizedSpriteList[SpriteIndex].Address;
/* Update the contents of this Sprite */
ROMFile.seekp (Address, ios::beg);
ROMFile.write((char*)(&RandomizedSpriteList[SpriteIndex].x), 1);
ROMFile.write((char*)(&RandomizedSpriteList[SpriteIndex].y), 1);
ROMFile.write((char*)(&RandomizedSpriteList[SpriteIndex].Orientation), 1);
ROMFile.write((char*)(&RandomizedSpriteList[SpriteIndex].Enemy), 1);
}
}
}