]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/Loader.cpp
non-reference type array relocation
[l2e.git] / src / loader / Loader.cpp
index 2403044ad20fb819a23fafc0b43c2ded125a317c..1e0050dbc022a64c1d7896428caad0b152dac2f0 100644 (file)
@@ -4,7 +4,9 @@
 #include <cstring>
 #include <fstream>
 #include <stdexcept>
+#include <utility>
 
+using std::make_pair;
 using std::map;
 using std::string;
 using std::vector;
@@ -52,6 +54,9 @@ void Loader::Load(const std::string &filePath) {
                LoadObjects(header->ident,
                                header->ObjectsBegin(),
                                header->ObjectsEnd());
+               LoadArrays(header->ident,
+                               header->ArraysBegin(),
+                               header->ArraysEnd());
        } catch (...) {
                delete[] block;
                throw;
@@ -65,6 +70,7 @@ void Loader::LoadExports(char *src, Export *begin, Export *end) {
                LoadedExport &exp(exports[identifier]);
                exp.typeId = i->typeId;
                exp.location = src + i->dataOffset;
+               exports.insert(make_pair(identifier, exp));
        }
 }
 
@@ -112,4 +118,22 @@ void Loader::LoadObject(char *src, char *object, const TypeDescription &td) {
        }
 }
 
+void Loader::LoadArrays(char *src, Array *begin, Array *end) {
+       for (Array *i = begin; i < end; i = i->Next()) {
+               if (i->ref) {
+                       for (char *j = i->Data(), *end = i->Data() + i->size;
+                                       j < end; j += sizeof(void *)) {
+                               *reinterpret_cast<char **>(j) =
+                                               src + *reinterpret_cast<unsigned int *>(j);
+                       }
+               } 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);
+                       }
+               }
+       }
+}
+
 }