9
3

opcodemgr.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef OPCODE_MANAGER_H
  17. #define OPCODE_MANAGER_H
  18. #include "types.h"
  19. #include "Mutex.h"
  20. #include "emu_opcodes.h"
  21. #include <map>
  22. using namespace std;
  23. class OpcodeManager {
  24. public:
  25. OpcodeManager();
  26. virtual ~OpcodeManager() {}
  27. virtual bool Mutable() { return(false); }
  28. virtual bool LoadOpcodes(const char *filename) = 0;
  29. virtual bool LoadOpcodes(map<string, uint16>* eq) = 0;
  30. virtual bool ReloadOpcodes(const char *filename) = 0;
  31. virtual uint16 EmuToEQ(const EmuOpcode emu_op) = 0;
  32. virtual EmuOpcode EQToEmu(const uint16 eq_op) = 0;
  33. static const char *EmuToName(const EmuOpcode emu_op);
  34. const char *EQToName(const uint16 emu_op);
  35. EmuOpcode NameSearch(const char *name);
  36. //This has to be public for stupid visual studio
  37. class OpcodeSetStrategy {
  38. public:
  39. virtual void Set(EmuOpcode emu_op, uint16 eq_op) = 0;
  40. virtual ~OpcodeSetStrategy(){}
  41. };
  42. protected:
  43. bool loaded; //true if all opcodes loaded
  44. Mutex MOpcodes; //this only protects the local machine
  45. //in a shared manager, this dosent protect others
  46. static bool LoadOpcodesFile(const char *filename, OpcodeSetStrategy *s);
  47. static bool LoadOpcodesMap(map<string, uint16>* eq, OpcodeSetStrategy *s);
  48. };
  49. class MutableOpcodeManager : public OpcodeManager {
  50. public:
  51. MutableOpcodeManager() : OpcodeManager() {}
  52. virtual bool Mutable() { return(true); }
  53. virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op) = 0;
  54. };
  55. #ifdef SHARED_OPCODES //quick toggle since only world and zone should possibly use this
  56. //keeps opcodes in shared memory
  57. class SharedOpcodeManager : public OpcodeManager {
  58. public:
  59. virtual ~SharedOpcodeManager() {}
  60. virtual bool LoadOpcodes(const char *filename);
  61. virtual bool LoadOpcodes(map<string, uint16>* eq);
  62. virtual bool ReloadOpcodes(const char *filename);
  63. virtual uint16 EmuToEQ(const EmuOpcode emu_op);
  64. virtual EmuOpcode EQToEmu(const uint16 eq_op);
  65. protected:
  66. class SharedMemStrategy : public OpcodeManager::OpcodeSetStrategy {
  67. public:
  68. void Set(EmuOpcode emu_op, uint16 eq_op);
  69. };
  70. static bool DLLLoadOpcodesCallback(const char *filename);
  71. };
  72. #endif //SHARED_OPCODES
  73. //keeps opcodes in regular heap memory
  74. class RegularOpcodeManager : public MutableOpcodeManager {
  75. public:
  76. RegularOpcodeManager();
  77. virtual ~RegularOpcodeManager();
  78. virtual bool Editable() { return(true); }
  79. virtual bool LoadOpcodes(const char *filename);
  80. virtual bool LoadOpcodes(map<string, uint16>* eq);
  81. virtual bool ReloadOpcodes(const char *filename);
  82. virtual uint16 EmuToEQ(const EmuOpcode emu_op);
  83. virtual EmuOpcode EQToEmu(const uint16 eq_op);
  84. //implement our editing interface
  85. virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op);
  86. protected:
  87. class NormalMemStrategy : public OpcodeManager::OpcodeSetStrategy {
  88. public:
  89. RegularOpcodeManager *it;
  90. void Set(EmuOpcode emu_op, uint16 eq_op);
  91. };
  92. friend class NormalMemStrategy;
  93. uint16 *emu_to_eq;
  94. EmuOpcode *eq_to_emu;
  95. uint32 EQOpcodeCount;
  96. uint32 EmuOpcodeCount;
  97. };
  98. //always resolves everything to 0 or OP_Unknown
  99. class NullOpcodeManager : public MutableOpcodeManager {
  100. public:
  101. NullOpcodeManager();
  102. virtual bool LoadOpcodes(const char *filename);
  103. virtual bool LoadOpcodes(map<string, uint16>* eq);
  104. virtual bool ReloadOpcodes(const char *filename);
  105. virtual uint16 EmuToEQ(const EmuOpcode emu_op);
  106. virtual EmuOpcode EQToEmu(const uint16 eq_op);
  107. //fake it, just used for testing anyways
  108. virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op) {}
  109. };
  110. //starts as NullOpcodeManager, but remembers any mappings set
  111. //could prolly have been implemented with an extension to regular,
  112. //by overriding its load methods to be empty.
  113. class EmptyOpcodeManager : public MutableOpcodeManager {
  114. public:
  115. EmptyOpcodeManager();
  116. virtual bool LoadOpcodes(const char *filename);
  117. virtual bool LoadOpcodes(map<string, uint16>* eq);
  118. virtual bool ReloadOpcodes(const char *filename);
  119. virtual uint16 EmuToEQ(const EmuOpcode emu_op);
  120. virtual EmuOpcode EQToEmu(const uint16 eq_op);
  121. //fake it, just used for testing anyways
  122. virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op);
  123. protected:
  124. map<EmuOpcode, uint16> emu_to_eq;
  125. map<uint16, EmuOpcode> eq_to_emu;
  126. };
  127. #endif