2015-05-19 21:54:34 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2005 Jonathon Fowler <jf@jonof.id.au>
|
|
|
|
|
|
|
|
This file is part of JFShadowWarrior
|
|
|
|
|
|
|
|
Shadow Warrior is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
#include "ns.h"
|
|
|
|
|
2020-01-22 21:49:51 +00:00
|
|
|
#include "tarray.h"
|
2020-05-21 14:25:41 +00:00
|
|
|
#include "debugbreak.h"
|
2019-10-09 17:58:09 +00:00
|
|
|
BEGIN_SW_NS
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "saveable.h"
|
|
|
|
|
2020-01-22 21:49:51 +00:00
|
|
|
static TArray<saveable_module*> saveablemodules;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
void Saveable_Init(void)
|
|
|
|
{
|
2020-01-22 21:49:51 +00:00
|
|
|
if (saveablemodules.Size() > 0) return;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
#define MODULE(x) { \
|
|
|
|
extern saveable_module saveable_ ## x; \
|
2020-01-22 21:49:51 +00:00
|
|
|
saveablemodules.Push(&saveable_ ## x); \
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MODULE(actor)
|
|
|
|
MODULE(ai)
|
2021-11-10 23:59:27 +00:00
|
|
|
MODULE(ai) // was 'build' but that is not used anywhere anymore.
|
2015-05-19 21:54:34 +00:00
|
|
|
MODULE(bunny)
|
|
|
|
MODULE(coolg)
|
|
|
|
MODULE(coolie)
|
|
|
|
MODULE(eel)
|
|
|
|
MODULE(girlninj)
|
|
|
|
MODULE(goro)
|
|
|
|
MODULE(hornet)
|
|
|
|
MODULE(jweapon)
|
|
|
|
MODULE(lava)
|
|
|
|
MODULE(miscactr)
|
|
|
|
MODULE(morph)
|
|
|
|
MODULE(ninja)
|
|
|
|
MODULE(panel)
|
|
|
|
MODULE(player)
|
|
|
|
MODULE(ripper)
|
|
|
|
MODULE(ripper2)
|
|
|
|
MODULE(rotator)
|
|
|
|
MODULE(serp)
|
|
|
|
MODULE(skel)
|
|
|
|
MODULE(skull)
|
|
|
|
MODULE(slidor)
|
|
|
|
MODULE(spike)
|
|
|
|
MODULE(sprite)
|
|
|
|
MODULE(sumo)
|
|
|
|
MODULE(track)
|
|
|
|
MODULE(vator)
|
|
|
|
MODULE(wallmove)
|
|
|
|
MODULE(weapon)
|
|
|
|
MODULE(zilla)
|
|
|
|
MODULE(zombie)
|
|
|
|
|
|
|
|
MODULE(sector)
|
|
|
|
}
|
|
|
|
|
|
|
|
int Saveable_FindCodeSym(void *ptr, savedcodesym *sym)
|
|
|
|
{
|
|
|
|
unsigned m,i;
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
{
|
2021-11-11 22:28:28 +00:00
|
|
|
sym->name = "";
|
2015-05-19 21:54:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:49:51 +00:00
|
|
|
for (m=0; m<saveablemodules.Size(); m++)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
for (i=0; i<saveablemodules[m]->numcode; i++)
|
|
|
|
{
|
2021-11-11 22:28:28 +00:00
|
|
|
if (ptr != saveablemodules[m]->code[i].base) continue;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-11-11 22:28:28 +00:00
|
|
|
sym->name = saveablemodules[m]->code[i].name;
|
2015-05-19 21:54:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 03:08:00 +00:00
|
|
|
debug_break();
|
2015-05-19 21:54:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Saveable_FindDataSym(void *ptr, saveddatasym *sym)
|
|
|
|
{
|
|
|
|
unsigned m,i;
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
{
|
2021-11-11 22:28:28 +00:00
|
|
|
sym->name = "";
|
2015-05-19 21:54:34 +00:00
|
|
|
sym->offset = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:49:51 +00:00
|
|
|
for (m = 0; m < saveablemodules.Size(); m++)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
for (i=0; i<saveablemodules[m]->numdata; i++)
|
|
|
|
{
|
|
|
|
if (ptr < saveablemodules[m]->data[i].base) continue;
|
|
|
|
if (ptr >= (void *)((intptr_t)saveablemodules[m]->data[i].base +
|
|
|
|
saveablemodules[m]->data[i].size)) continue;
|
|
|
|
|
2021-11-11 22:28:28 +00:00
|
|
|
sym->name = saveablemodules[m]->data[i].name;
|
2021-05-12 14:50:20 +00:00
|
|
|
sym->offset = unsigned((intptr_t)ptr - (intptr_t)saveablemodules[m]->data[i].base);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2020-02-19 03:08:00 +00:00
|
|
|
|
|
|
|
debug_break();
|
2015-05-19 21:54:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Saveable_RestoreCodeSym(savedcodesym *sym, void **ptr)
|
|
|
|
{
|
2021-11-11 22:28:28 +00:00
|
|
|
if (sym->name.IsEmpty())
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-07-10 12:25:18 +00:00
|
|
|
*ptr = nullptr;
|
2015-05-19 21:54:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-11 22:28:28 +00:00
|
|
|
for (auto module : saveablemodules)
|
2020-02-19 03:08:00 +00:00
|
|
|
{
|
2021-11-11 22:28:28 +00:00
|
|
|
for (unsigned i = 0; i < module->numcode; i++)
|
|
|
|
{
|
|
|
|
if (sym->name.Compare(module->code[i].name) == 0)
|
|
|
|
{
|
|
|
|
*ptr = module->code[i].base;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2020-02-19 03:08:00 +00:00
|
|
|
}
|
2021-11-11 22:28:28 +00:00
|
|
|
I_Error("Unknown code reference '%s' in savegame\n", sym->name.GetChars());
|
|
|
|
return -1;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Saveable_RestoreDataSym(saveddatasym *sym, void **ptr)
|
|
|
|
{
|
2021-11-11 22:28:28 +00:00
|
|
|
if (sym->name.IsEmpty())
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-07-10 12:25:18 +00:00
|
|
|
*ptr = nullptr;
|
2015-05-19 21:54:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-11 22:28:28 +00:00
|
|
|
for (auto module : saveablemodules)
|
2020-02-19 03:08:00 +00:00
|
|
|
{
|
2021-11-11 22:28:28 +00:00
|
|
|
for (unsigned i = 0; i < module->numdata; i++)
|
|
|
|
{
|
|
|
|
if (sym->name.Compare(module->data[i].name) == 0)
|
|
|
|
{
|
|
|
|
*ptr = ((uint8_t*)module->data[i].base) + sym->offset;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2020-02-19 03:08:00 +00:00
|
|
|
}
|
2021-11-11 22:28:28 +00:00
|
|
|
I_Error("Unknown data reference '%s' in savegame\n", sym->name.GetChars());
|
|
|
|
return -1;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
2021-11-11 22:28:28 +00:00
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
END_SW_NS
|