+ if (i->ref) {
+ for (char *j = i->Data(), *end = i->Data() + i->size;
+ j < end; j += sizeof(void *)) {
+ unsigned int offset = *reinterpret_cast<unsigned int *>(j);
+ if (offset) {
+ *reinterpret_cast<char **>(j) = src + offset;
+ }
+ }
+ } else {
+ const TypeDescription &td = TypeDescription::Get(i->typeId);
+ for (char *j = i->Data(), *end = i->Data() + i->size;
+ j < end; j += td.Size()) {
+ LoadObject(src, j, td);
+ }
+ }
+ }
+}
+
+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);
+ }
+}
+
+void Loader::InitArrays(Array *begin, Array *end) {
+ for (Array *i = begin; i < end; i = i->Next()) {
+ if (i->ref) {