-void Loader::LoadImages(LoadedObjectFile &object) {
- for (char *i(object.imagesBegin); i != object.imagesEnd;) {
- ImageProperties *props(reinterpret_cast<ImageProperties *>(i));
- i += sizeof(ImageProperties) + props->width * props->height * (props->depth / CHAR_BIT + (props->depth % CHAR_BIT ? 1 : 0));
- ++object.surfaceCount;
- }
- if (object.surfaceCount == 0) return;
-
- object.surfaces = new SDL_Surface *[object.surfaceCount];
- int index(0);
- for (char *i(object.imagesBegin); i != object.imagesEnd;) {
- ImageProperties *props(reinterpret_cast<ImageProperties *>(i));
- i += sizeof(ImageProperties);
- SDL_Surface *image(SDL_CreateRGBSurfaceFrom(
- i,
- props->width,
- props->height,
- props->depth,
- props->pitch,
- props->rmask,
- props->gmask,
- props->bmask,
- props->amask));
- i += props->width * props->height * (props->depth / CHAR_BIT + (props->depth % CHAR_BIT ? 1 : 0));
- object.surfaces[index] = image;
- ++index;
+void Loader::LoadScripts(char *src, Script *begin, Script *end) {
+ for (Script *s = begin; s < end; s = s->Next()) {
+ for (char *i = s->Text(), *end = s->Text() + s->size; i < end;) {
+ common::Script::Code *code =
+ reinterpret_cast<common::Script::Code *>(i);
+ if (code->type == common::Script::TYPE_ADDRESS && code->numParams > 0) {
+ if (code->reg1 == 7) {
+ char *addr = i + sizeof(common::Script::Code);
+ unsigned int offset = *reinterpret_cast<unsigned int *>(addr);
+ if (offset) {
+ *reinterpret_cast<const char **>(addr) = src + offset;
+ }
+ }
+
+ if (code->numParams > 1 && code->reg2 == 7) {
+ char *addr = i + sizeof(common::Script::Code);
+ if (code->reg1 == 7) {
+ addr += sizeof(void *);
+ }
+ unsigned int offset = *reinterpret_cast<unsigned int *>(addr);
+ if (offset) {
+ *reinterpret_cast<const char **>(addr) = src + offset;
+ }
+ }
+ }
+ i += code->Size();
+ }
+ }
+}
+
+
+void Loader::InitObjects(Object *begin, Object *end) {
+ for (Object *i = begin; i < end; i = i->Next()) {
+ const TypeDescription &td =
+ TypeDescription::Get(i->typeId);
+ InitObject(i->RawObject(), td);
+ }
+}
+
+void Loader::InitObject(char *object, const TypeDescription &td) {
+ td.Init(object);
+ td.Load(object);
+ for (TypeDescription::FieldIterator
+ i(td.FieldsBegin()), end(td.FieldsEnd());
+ i != end; ++i) {
+ const FieldDescription &field = i->second;
+ if (field.IsReferenced() || field.IsAggregate()) {
+ continue;
+ }
+ const TypeDescription &nestedType
+ = TypeDescription::Get(field.TypeId());
+ InitObject(object + field.Offset(), nestedType);