]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/Compiler.cpp
non-reference type array relocation
[l2e.git] / src / loader / Compiler.cpp
index 95d41ccadceb3ab6a5dc3b558cb1ceaa2716463c..b583aabb298a46017fb87d23d1772e1e79fed12e 100644 (file)
@@ -141,6 +141,7 @@ void Compiler::WriteArrays(ostream &out) {
                        i(intp.Arrays().begin()), end(intp.Arrays().end());
                        i != end; ++i) {
                Array array;
+               array.typeId = i->typeId;
                array.size = i->size;
                array.ref = i->ref;
                Write(out, &array, sizeof(Array));
@@ -210,19 +211,23 @@ void Compiler::Relocate(iostream &out) {
        Array array;
        for (; out && out.tellg() < fileHeader.arraysEnd;) {
                out.read(reinterpret_cast<char *>(&array), sizeof(Array));
-               if (!array.ref) {
-                       out.seekg(array.size);
-                       continue;
+               if (array.ref) {
+                       buffer = new char[array.size];
+                       unsigned int pos = out.tellg();
+                       out.seekg(pos);
+                       out.read(buffer, array.size);
+                       RelocateArray(buffer, array.size);
+                       out.seekp(pos);
+                       out.write(buffer, array.size);
+                       out.seekg(out.tellp());
+                       delete[] buffer;
+               } else {
+                       const TypeDescription &td = TypeDescription::Get(array.typeId);
+                       for (char *i = array.Data(), *end = array.Data() + array.size;
+                                       i < end; i += td.Size()) {
+                               Relocate(i, td);
+                       }
                }
-               buffer = new char[array.size];
-               unsigned int pos = out.tellg();
-               out.seekg(pos);
-               out.read(buffer, array.size);
-               RelocateArray(buffer, array.size);
-               out.seekp(pos);
-               out.write(buffer, array.size);
-               out.seekg(out.tellp());
-               delete[] buffer;
        }
 }